Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gtts import gTTS
|
3 |
+
from io import BytesIO
|
4 |
+
import IPython.display as ipd
|
5 |
+
|
6 |
+
Load model
|
7 |
+
codellama_model = gr.Interface.load("models/meta-llama/CodeLlama-7b-Python-hf")
|
8 |
+
deepseek_model = gr.Interface.load("models/deepseek-ai/deepseek-coder-1.3b-instruct")
|
9 |
+
|
10 |
+
def process_text_codellama(input_text):
|
11 |
+
return codellama_model.predict(input_text)
|
12 |
+
|
13 |
+
def process_speech_codellama(audio):
|
14 |
+
response = codellama_model.predict(audio)
|
15 |
+
tts = gTTS(text=response, lang='en')
|
16 |
+
fp = BytesIO()
|
17 |
+
tts.write_to_fp(fp)
|
18 |
+
fp.seek(0)
|
19 |
+
return ipd.Audio(fp.read(), autoplay=True)
|
20 |
+
|
21 |
+
def process_text_deepseek(input_text):
|
22 |
+
return deepseek_model.predict(input_text)
|
23 |
+
|
24 |
+
def process_speech_deepseek(audio):
|
25 |
+
response = deepseek_model.predict(audio)
|
26 |
+
tts = gTTS(text=response, lang='en')
|
27 |
+
fp = BytesIO()
|
28 |
+
tts.write_to_fp(fp)
|
29 |
+
fp.seek(0)
|
30 |
+
return ipd.Audio(fp.read(), autoplay=True)
|
31 |
+
|
32 |
+
def main(input_text):
|
33 |
+
if input_text[1]:
|
34 |
+
return process_text_deepseek(input_text[0]), process_speech_deepseek(input_text[0])
|
35 |
+
else:
|
36 |
+
return process_text_codellama(input_text[0]), process_speech_codellama(input_text[0])
|
37 |
+
|
38 |
+
gr.Interface(
|
39 |
+
fn=main,
|
40 |
+
inputs=["text", "checkbox"], # ["input text", "enable voice input"]
|
41 |
+
outputs=["text", "audio"],
|
42 |
+
live=True
|
43 |
+
).launch()
|