Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import torch
|
|
4 |
import tempfile
|
5 |
import asyncio
|
6 |
import edge_tts
|
|
|
7 |
from pydub import AudioSegment
|
8 |
from threading import Thread
|
9 |
from collections.abc import Iterator
|
@@ -45,7 +46,8 @@ async def text_to_speech(text: str) -> str:
|
|
45 |
|
46 |
os.remove(wav_path) # Delete the original WAV file
|
47 |
return mp3_path # Return the MP3 file path
|
48 |
-
|
|
|
49 |
def generate(
|
50 |
message: str,
|
51 |
chat_history: list[dict],
|
@@ -61,7 +63,7 @@ def generate(
|
|
61 |
|
62 |
# Remove special tags
|
63 |
if is_tts:
|
64 |
-
message = message.replace("
|
65 |
elif is_text_only:
|
66 |
message = message.replace("@text", "").strip()
|
67 |
|
@@ -100,9 +102,9 @@ def generate(
|
|
100 |
loop = asyncio.new_event_loop()
|
101 |
asyncio.set_event_loop(loop)
|
102 |
audio_path = loop.run_until_complete(text_to_speech(final_output))
|
103 |
-
return audio_path
|
104 |
|
105 |
-
return final_output #
|
106 |
|
107 |
demo = gr.ChatInterface(
|
108 |
fn=generate,
|
@@ -117,7 +119,7 @@ demo = gr.ChatInterface(
|
|
117 |
examples=[
|
118 |
["A train travels 60 kilometers per hour. If it travels for 5 hours, how far will it travel in total?"],
|
119 |
["@text What is AI?"],
|
120 |
-
["
|
121 |
["@text Rewrite the following sentence in passive voice: 'The dog chased the cat.'"],
|
122 |
],
|
123 |
cache_examples=False,
|
|
|
4 |
import tempfile
|
5 |
import asyncio
|
6 |
import edge_tts
|
7 |
+
import spaces
|
8 |
from pydub import AudioSegment
|
9 |
from threading import Thread
|
10 |
from collections.abc import Iterator
|
|
|
46 |
|
47 |
os.remove(wav_path) # Delete the original WAV file
|
48 |
return mp3_path # Return the MP3 file path
|
49 |
+
|
50 |
+
@spaces.GPU
|
51 |
def generate(
|
52 |
message: str,
|
53 |
chat_history: list[dict],
|
|
|
63 |
|
64 |
# Remove special tags
|
65 |
if is_tts:
|
66 |
+
message = message.replace("@tts", "").strip()
|
67 |
elif is_text_only:
|
68 |
message = message.replace("@text", "").strip()
|
69 |
|
|
|
102 |
loop = asyncio.new_event_loop()
|
103 |
asyncio.set_event_loop(loop)
|
104 |
audio_path = loop.run_until_complete(text_to_speech(final_output))
|
105 |
+
return audio_path
|
106 |
|
107 |
+
return final_output #
|
108 |
|
109 |
demo = gr.ChatInterface(
|
110 |
fn=generate,
|
|
|
119 |
examples=[
|
120 |
["A train travels 60 kilometers per hour. If it travels for 5 hours, how far will it travel in total?"],
|
121 |
["@text What is AI?"],
|
122 |
+
["@tts Explain Newton's third law of motion."],
|
123 |
["@text Rewrite the following sentence in passive voice: 'The dog chased the cat.'"],
|
124 |
],
|
125 |
cache_examples=False,
|