Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
from gtts import gTTS
|
| 5 |
import tempfile
|
| 6 |
import time
|
| 7 |
|
| 8 |
-
|
| 9 |
# Configure the Gemini API
|
| 10 |
GOOGLE_API_KEY = os.getenv("gemini_api") # Replace with your actual API key
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
# Initialize the model
|
| 14 |
model = genai.GenerativeModel('gemini-pro')
|
|
@@ -21,7 +21,12 @@ def transcribe_audio(audio_path):
|
|
| 21 |
"""
|
| 22 |
# For demonstration, we're returning a placeholder message
|
| 23 |
# In a real app, you would connect to a speech-to-text service
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def text_to_speech(text):
|
| 27 |
"""Convert text to speech using gTTS and return the path to the audio file"""
|
|
@@ -37,13 +42,9 @@ def chat_with_gemini(user_input, history):
|
|
| 37 |
# Initialize conversation or continue existing one
|
| 38 |
if not history:
|
| 39 |
history = []
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
chat = model.start_chat(history=[
|
| 44 |
-
{"role": "user" if i % 2 == 0 else "model", "parts": [msg]}
|
| 45 |
-
for i, msg in enumerate(history)
|
| 46 |
-
])
|
| 47 |
|
| 48 |
# Generate response
|
| 49 |
response = chat.send_message(user_input)
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from google import genai
|
| 4 |
from gtts import gTTS
|
| 5 |
import tempfile
|
| 6 |
import time
|
| 7 |
|
|
|
|
| 8 |
# Configure the Gemini API
|
| 9 |
GOOGLE_API_KEY = os.getenv("gemini_api") # Replace with your actual API key
|
| 10 |
+
|
| 11 |
+
client = genai.Client(api_key=GOOGLE_API_KEY)
|
| 12 |
|
| 13 |
# Initialize the model
|
| 14 |
model = genai.GenerativeModel('gemini-pro')
|
|
|
|
| 21 |
"""
|
| 22 |
# For demonstration, we're returning a placeholder message
|
| 23 |
# In a real app, you would connect to a speech-to-text service
|
| 24 |
+
response = client.models.generate_content(
|
| 25 |
+
model='gemini-2.0-flash',
|
| 26 |
+
contents=['Describe this audio clip', audio_path]
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
return response.text
|
| 30 |
|
| 31 |
def text_to_speech(text):
|
| 32 |
"""Convert text to speech using gTTS and return the path to the audio file"""
|
|
|
|
| 42 |
# Initialize conversation or continue existing one
|
| 43 |
if not history:
|
| 44 |
history = []
|
| 45 |
+
|
| 46 |
+
chat = client.chats.create(model="gemini-2.0-flash")
|
| 47 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# Generate response
|
| 50 |
response = chat.send_message(user_input)
|