Update app.py
Browse files
app.py
CHANGED
@@ -11,18 +11,54 @@ chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
|
|
11 |
|
12 |
# tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
|
13 |
# model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def chat_with_bot(user_input):
|
16 |
# Generate a response from the chatbot model
|
17 |
response = chatbot(user_input)
|
18 |
return response[0]['generated_text']
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
interface = gr.Interface(
|
21 |
-
fn=
|
22 |
-
inputs=gr.
|
23 |
-
outputs=gr.
|
24 |
-
|
25 |
-
description="Chat with an AI model powered by DialoGPT!" # Optional: Add a description
|
26 |
)
|
27 |
|
28 |
interface.launch()
|
|
|
11 |
|
12 |
# tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
|
13 |
# model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
|
14 |
+
stt_model = get_stt_model()
|
15 |
+
tts_model = get_tts_model()
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
stream = Stream(ReplyOnPause(echo), modality="audio", mode="send-receive")
|
20 |
+
|
21 |
+
|
22 |
+
def echo(audio):
|
23 |
+
prompt = stt_model.stt(audio)
|
24 |
+
# response = sambanova_client.chat.completions.create(
|
25 |
+
# model="Meta-Llama-3.2-3B-Instruct",
|
26 |
+
# messages=[{"role": "user", "content": prompt}],
|
27 |
+
# max_tokens=200,
|
28 |
+
# )
|
29 |
+
# prompt = response.choices[0].message.content
|
30 |
+
prompt = chat_with_bot(prompt)
|
31 |
+
for audio_chunk in tts_model.stream_tts_sync(prompt):
|
32 |
+
yield audio_chunk
|
33 |
+
def process_audio(audio_input):
|
34 |
+
# audio_input is received as a Gradio Audio object, containing a tuple of (sample_rate, numpy array)
|
35 |
+
sample_rate, audio_data = audio_input
|
36 |
+
|
37 |
+
# Process audio through the stream
|
38 |
+
processed_sample_rate, processed_audio = echo((sample_rate, audio_data))
|
39 |
+
|
40 |
+
# Return processed audio to Gradio for output
|
41 |
+
return processed_sample_rate, processed_audio
|
42 |
+
|
43 |
|
44 |
def chat_with_bot(user_input):
|
45 |
# Generate a response from the chatbot model
|
46 |
response = chatbot(user_input)
|
47 |
return response[0]['generated_text']
|
48 |
|
49 |
+
# interface = gr.Interface(
|
50 |
+
# fn=chat_with_bot, # Function to call for processing the input
|
51 |
+
# inputs=gr.Textbox(label="Enter your message"), # User input (text)
|
52 |
+
# outputs=gr.Textbox(label="Chatbot Response"), # Model output (text)
|
53 |
+
# title="Chat with DialoGPT", # Optional: Add a title to your interface
|
54 |
+
# description="Chat with an AI model powered by DialoGPT!" # Optional: Add a description
|
55 |
+
# )
|
56 |
+
|
57 |
interface = gr.Interface(
|
58 |
+
fn=process_audio, # The function to process audio
|
59 |
+
inputs=gr.Audio(type="numpy"), # Microphone input (audio)
|
60 |
+
outputs=gr.Audio(type="numpy"), # Audio output (processed)
|
61 |
+
live=True # Make the processing live (if needed)
|
|
|
62 |
)
|
63 |
|
64 |
interface.launch()
|