Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
-
from gtts import gTTS
|
4 |
-
import base64
|
5 |
-
from io import BytesIO
|
6 |
from transformers import pipeline
|
7 |
#https://huggingface.co/facebook/opt-1.3b
|
8 |
generator = pipeline('text-generation', model="facebook/opt-1.3b")
|
@@ -15,24 +12,13 @@ def create_audio(input_str):
|
|
15 |
output_str = output_str.replace("\n", "")
|
16 |
output_str = output_str.replace(input_str, "")
|
17 |
|
18 |
-
|
19 |
-
tts = gTTS(text=output_str, lang="en")
|
20 |
-
# Save the speech as a bytestring in memory
|
21 |
-
tts_io = BytesIO()
|
22 |
-
tts.write_to_fp(tts_io)
|
23 |
-
tts_io.seek(0)
|
24 |
-
tts_data = tts_io.read()
|
25 |
-
# Encode the speech data in base64
|
26 |
-
tts_base64 = base64.b64encode(tts_data).decode("utf-8")
|
27 |
-
# Return the html code to play the audio
|
28 |
-
html = f"<audio src='data:audio/mpeg;base64,{tts_base64}' controls autoplay></audio>"
|
29 |
-
return (output_raw, html)
|
30 |
|
31 |
demo = gr.Interface(
|
32 |
fn=create_audio,
|
33 |
inputs="text",
|
34 |
-
outputs=
|
35 |
-
title="
|
36 |
description="This interface generates a random audio sentence and plays it as a html output."
|
37 |
)
|
38 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import random
|
|
|
|
|
|
|
3 |
from transformers import pipeline
|
4 |
#https://huggingface.co/facebook/opt-1.3b
|
5 |
generator = pipeline('text-generation', model="facebook/opt-1.3b")
|
|
|
12 |
output_str = output_str.replace("\n", "")
|
13 |
output_str = output_str.replace(input_str, "")
|
14 |
|
15 |
+
return (output_str)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
demo = gr.Interface(
|
18 |
fn=create_audio,
|
19 |
inputs="text",
|
20 |
+
outputs="text",
|
21 |
+
title="LLM",
|
22 |
description="This interface generates a random audio sentence and plays it as a html output."
|
23 |
)
|
24 |
demo.launch()
|