Ath
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -8,17 +8,17 @@ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
|
8 |
|
9 |
# Create the model
|
10 |
generation_config = {
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
}
|
17 |
|
18 |
model = genai.GenerativeModel(
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
)
|
23 |
|
24 |
chat_session = model.start_chat(history=[])
|
@@ -27,7 +27,7 @@ chat_session = model.start_chat(history=[])
|
|
27 |
eleven_labs_api_key = os.getenv("ELEVEN_LABS_API_KEY")
|
28 |
eleven_labs_url = "https://api.elevenlabs.io/v1/text-to-speech/aEO01A4wXwd1O8GPgGlF"
|
29 |
|
30 |
-
def chat_and_tts(user_input):
|
31 |
# Send the user's input to the chat session
|
32 |
response = chat_session.send_message(user_input)
|
33 |
response_text = response.text
|
@@ -53,24 +53,30 @@ def chat_and_tts(user_input):
|
|
53 |
audio_path = 'response_audio.mp3'
|
54 |
with open(audio_path, 'wb') as file:
|
55 |
file.write(tts_response.content)
|
56 |
-
return response_text, audio_path
|
57 |
else:
|
58 |
-
|
59 |
|
60 |
-
#
|
61 |
-
|
62 |
-
|
63 |
-
return
|
64 |
|
65 |
# Create the Gradio UI
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
|
76 |
-
iface.launch()
|
|
|
8 |
|
9 |
# Create the model
|
10 |
generation_config = {
|
11 |
+
"temperature": 1,
|
12 |
+
"top_p": 0.95,
|
13 |
+
"top_k": 64,
|
14 |
+
"max_output_tokens": 8192,
|
15 |
+
"response_mime_type": "text/plain",
|
16 |
}
|
17 |
|
18 |
model = genai.GenerativeModel(
|
19 |
+
model_name="gemini-1.5-pro",
|
20 |
+
generation_config=generation_config,
|
21 |
+
system_instruction="You are a human, living on Earth. You speak friendly and use casual language. You never say you're an AI or program. Your name is Ath, and you always speak like a 100% human.",
|
22 |
)
|
23 |
|
24 |
chat_session = model.start_chat(history=[])
|
|
|
27 |
eleven_labs_api_key = os.getenv("ELEVEN_LABS_API_KEY")
|
28 |
eleven_labs_url = "https://api.elevenlabs.io/v1/text-to-speech/aEO01A4wXwd1O8GPgGlF"
|
29 |
|
30 |
+
def chat_and_tts(user_input, history):
|
31 |
# Send the user's input to the chat session
|
32 |
response = chat_session.send_message(user_input)
|
33 |
response_text = response.text
|
|
|
53 |
audio_path = 'response_audio.mp3'
|
54 |
with open(audio_path, 'wb') as file:
|
55 |
file.write(tts_response.content)
|
|
|
56 |
else:
|
57 |
+
audio_path = None
|
58 |
|
59 |
+
# Update the chat history
|
60 |
+
history.append((user_input, response_text))
|
61 |
+
|
62 |
+
return history, history, audio_path
|
63 |
|
64 |
# Create the Gradio UI
|
65 |
+
with gr.Blocks() as demo:
|
66 |
+
gr.Markdown("<h1 style='text-align: center;'>Chat with Ath</h1>")
|
67 |
+
gr.Markdown("Ask any question and get a friendly response from Ath. The response will also be converted to speech.")
|
68 |
+
|
69 |
+
with gr.Row():
|
70 |
+
with gr.Column(scale=2):
|
71 |
+
chatbot = gr.Chatbot(label="Chat History")
|
72 |
+
user_input = gr.Textbox(placeholder="Ask me anything...", label="Your Question")
|
73 |
+
submit_btn = gr.Button("Send")
|
74 |
+
|
75 |
+
with gr.Column(scale=1):
|
76 |
+
audio_output = gr.Audio(label="Response Audio")
|
77 |
+
|
78 |
+
state = gr.State([])
|
79 |
+
|
80 |
+
submit_btn.click(chat_and_tts, inputs=[user_input, state], outputs=[chatbot, state, audio_output])
|
81 |
|
82 |
+
demo.launch()
|
|