Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import os
|
|
2 |
import gradio as gr
|
3 |
from groq import Groq
|
4 |
|
5 |
-
# Retrieve API key from environment variable
|
6 |
api_key = os.getenv("GROQ_API_KEY")
|
7 |
client = Groq(api_key=api_key)
|
8 |
|
@@ -49,10 +48,8 @@ def process_input(audio_file, text_input, chat_history):
|
|
49 |
chat_history.append(("👤", transcription_text))
|
50 |
chat_history.append(("🤖", chat_response))
|
51 |
|
52 |
-
# Format chat history for display
|
53 |
formatted_history = "\n".join([f"{role}: {content}\n" for role, content in chat_history])
|
54 |
|
55 |
-
# Reset the inputs after processing
|
56 |
return formatted_history, gr.update(value=None), gr.update(value=''), chat_history
|
57 |
|
58 |
# Create Gradio interface
|
@@ -61,13 +58,13 @@ interface = gr.Interface(
|
|
61 |
inputs=[
|
62 |
gr.Audio(type="filepath", label="Upload Audio or Record"),
|
63 |
gr.Textbox(lines=2, placeholder="Or type text here", label="Text Input"),
|
64 |
-
gr.State([])
|
65 |
],
|
66 |
outputs=[
|
67 |
gr.Textbox(label="Chat History", lines=20),
|
68 |
-
gr.Audio(visible=False),
|
69 |
-
gr.Textbox(visible=False),
|
70 |
-
gr.State()
|
71 |
],
|
72 |
title="Chat with Llama 3.1-8B With Text or Voice (Whisper Large-v3)",
|
73 |
description="Upload an audio file or type text to get a chat response based on the transcription.",
|
@@ -75,4 +72,4 @@ interface = gr.Interface(
|
|
75 |
)
|
76 |
|
77 |
if __name__ == "__main__":
|
78 |
-
interface.launch()
|
|
|
2 |
import gradio as gr
|
3 |
from groq import Groq
|
4 |
|
|
|
5 |
api_key = os.getenv("GROQ_API_KEY")
|
6 |
client = Groq(api_key=api_key)
|
7 |
|
|
|
48 |
chat_history.append(("👤", transcription_text))
|
49 |
chat_history.append(("🤖", chat_response))
|
50 |
|
|
|
51 |
formatted_history = "\n".join([f"{role}: {content}\n" for role, content in chat_history])
|
52 |
|
|
|
53 |
return formatted_history, gr.update(value=None), gr.update(value=''), chat_history
|
54 |
|
55 |
# Create Gradio interface
|
|
|
58 |
inputs=[
|
59 |
gr.Audio(type="filepath", label="Upload Audio or Record"),
|
60 |
gr.Textbox(lines=2, placeholder="Or type text here", label="Text Input"),
|
61 |
+
gr.State([])
|
62 |
],
|
63 |
outputs=[
|
64 |
gr.Textbox(label="Chat History", lines=20),
|
65 |
+
gr.Audio(visible=False),
|
66 |
+
gr.Textbox(visible=False),
|
67 |
+
gr.State()
|
68 |
],
|
69 |
title="Chat with Llama 3.1-8B With Text or Voice (Whisper Large-v3)",
|
70 |
description="Upload an audio file or type text to get a chat response based on the transcription.",
|
|
|
72 |
)
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
+
interface.launch()
|