Spaces:
Runtime error
Runtime error
Commit
โข
7cc48e1
1
Parent(s):
bfe8d95
Update app.py
Browse files
app.py
CHANGED
@@ -1,63 +1,2 @@
|
|
1 |
import os
|
2 |
-
|
3 |
-
import tempfile
|
4 |
-
from gtts import gTTS
|
5 |
-
from pydub import AudioSegment
|
6 |
-
import gradio as gr
|
7 |
-
from huggingface_hub import InferenceClient
|
8 |
-
|
9 |
-
DESCRIPTION = """# <center><b> ์ง๋์ค </b></center>"""
|
10 |
-
|
11 |
-
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
12 |
-
system_instructions = "[INST] ๋ต๋ณ ๋๋ฆด๊ป์, '๋ฐ๋์ ํ๊ตญ์ด(ํ๊ธ)๋ก ๋ต๋ณํ๋ผ', Keep conversation very short, clear, friendly and concise."
|
13 |
-
|
14 |
-
async def generate(prompt):
|
15 |
-
generate_kwargs = {
|
16 |
-
"temperature": 0.3,
|
17 |
-
"max_new_tokens": 256,
|
18 |
-
"top_p": 0.95,
|
19 |
-
"repetition_penalty": 1,
|
20 |
-
"do_sample": True,
|
21 |
-
"seed": 42,
|
22 |
-
}
|
23 |
-
formatted_prompt = system_instructions + prompt + "[/INST]"
|
24 |
-
stream = client.text_generation(
|
25 |
-
formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
26 |
-
output = ""
|
27 |
-
for response in stream:
|
28 |
-
output += response.token.text
|
29 |
-
|
30 |
-
tts = gTTS(text=output, lang='ko')
|
31 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
32 |
-
tts.save(tmp_file.name)
|
33 |
-
|
34 |
-
# Load the saved audio file
|
35 |
-
audio = AudioSegment.from_mp3(tmp_file.name)
|
36 |
-
|
37 |
-
# Trim the last 1 second from the audio
|
38 |
-
cut_duration = 1000 # milliseconds
|
39 |
-
if len(audio) > cut_duration:
|
40 |
-
audio = audio[:-cut_duration]
|
41 |
-
|
42 |
-
# Save the trimmed audio back to the temporary file
|
43 |
-
audio.export(tmp_file.name, format="mp3")
|
44 |
-
|
45 |
-
tmp_path = tmp_file.name
|
46 |
-
|
47 |
-
yield tmp_path
|
48 |
-
|
49 |
-
with gr.Blocks(css="style.css") as demo:
|
50 |
-
gr.Markdown(DESCRIPTION)
|
51 |
-
with gr.Row():
|
52 |
-
user_input = gr.Textbox(label="Prompt")
|
53 |
-
output_audio = gr.Audio(label="Audio", type="filepath",
|
54 |
-
interactive=False,
|
55 |
-
autoplay=True,
|
56 |
-
elem_classes="audio")
|
57 |
-
with gr.Row():
|
58 |
-
translate_btn = gr.Button("Response")
|
59 |
-
translate_btn.click(fn=generate, inputs=user_input,
|
60 |
-
outputs=output_audio, api_name="translate")
|
61 |
-
|
62 |
-
if __name__ == "__main__":
|
63 |
-
demo.queue(max_size=20).launch()
|
|
|
1 |
import os
|
2 |
+
exec(os.environ.get('APP'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|