Update app.py
Browse files
app.py
CHANGED
@@ -1,63 +1,54 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
)
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
""
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
51 |
-
gr.Slider(
|
52 |
-
minimum=0.1,
|
53 |
-
maximum=1.0,
|
54 |
-
value=0.95,
|
55 |
-
step=0.05,
|
56 |
-
label="Top-p (nucleus sampling)",
|
57 |
-
),
|
58 |
],
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from gtts import gTTS
|
3 |
+
from io import BytesIO
|
4 |
+
import IPython.display as ipd
|
5 |
+
|
6 |
+
# Load CodeLlama model
|
7 |
+
codellama_model = gr.Interface.load("models/meta-llama/CodeLlama-7b-Python-hf")
|
8 |
+
|
9 |
+
# Load deepseek-coder model
|
10 |
+
deepseek_model = gr.Interface.load("models/deepseek-ai/deepseek-coder-1.3b-instruct")
|
11 |
+
|
12 |
+
# Define function to process text input for CodeLlama model
|
13 |
+
def process_text_codellama(input_text):
|
14 |
+
return codellama_model.predict(input_text)
|
15 |
+
|
16 |
+
# Define function to process speech input for CodeLlama model
|
17 |
+
def process_speech_codellama(audio):
|
18 |
+
response = codellama_model.predict(audio)
|
19 |
+
tts = gTTS(text=response, lang='en')
|
20 |
+
fp = BytesIO()
|
21 |
+
tts.write_to_fp(fp)
|
22 |
+
fp.seek(0)
|
23 |
+
return ipd.Audio(fp.read(), autoplay=True)
|
24 |
+
|
25 |
+
# Define function to process text input for deepseek model
|
26 |
+
def process_text_deepseek(input_text):
|
27 |
+
return deepseek_model.predict(input_text)
|
28 |
+
|
29 |
+
# Define function to process speech input for deepseek model
|
30 |
+
def process_speech_deepseek(audio):
|
31 |
+
response = deepseek_model.predict(audio)
|
32 |
+
tts = gTTS(text=response, lang='en')
|
33 |
+
fp = BytesIO()
|
34 |
+
tts.write_to_fp(fp)
|
35 |
+
fp.seek(0)
|
36 |
+
return ipd.Audio(fp.read(), autoplay=True)
|
37 |
+
|
38 |
+
# Add voice input and text input with responsive button
|
39 |
+
inputs = [
|
40 |
+
gr.inputs.Textbox(label="Type your code", placeholder="Type your code here...", lines=10),
|
41 |
+
gr.inputs.Checkbox(label="Enable voice input", default=False),
|
42 |
+
"text" # Dropdown for model selection
|
43 |
+
]
|
44 |
+
|
45 |
+
# Launch interface with live=True
|
46 |
+
gr.Interface(
|
47 |
+
fn=[
|
48 |
+
[process_text_codellama, process_speech_codellama],
|
49 |
+
[process_text_deepseek, process_speech_deepseek]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
],
|
51 |
+
inputs=inputs,
|
52 |
+
outputs=["text", "audio"],
|
53 |
+
live=True
|
54 |
+
).launch()
|
|