Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
| 3 |
import os
|
| 4 |
-
import
|
| 5 |
|
| 6 |
# Set OpenAI API Key
|
| 7 |
openai.api_key = os.getenv("TRY_NEW_THINGS")
|
|
@@ -22,18 +22,12 @@ def get_groq_response(message):
|
|
| 22 |
return f"Error: {str(e)}"
|
| 23 |
|
| 24 |
# Function to convert speech to text
|
|
|
|
| 25 |
def speech_to_text(audio):
|
| 26 |
-
#
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
# Convert audio to text
|
| 30 |
-
try:
|
| 31 |
-
with sr.AudioFile(audio.name) as source:
|
| 32 |
-
audio_data = recognizer.record(source)
|
| 33 |
-
text = recognizer.recognize_google(audio_data)
|
| 34 |
-
return text
|
| 35 |
-
except Exception as e:
|
| 36 |
-
return f"Error in speech recognition: {str(e)}"
|
| 37 |
|
| 38 |
# Chatbot function
|
| 39 |
def chatbot(user_input, history=[]):
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
| 3 |
import os
|
| 4 |
+
import openai-whisper
|
| 5 |
|
| 6 |
# Set OpenAI API Key
|
| 7 |
openai.api_key = os.getenv("TRY_NEW_THINGS")
|
|
|
|
| 22 |
return f"Error: {str(e)}"
|
| 23 |
|
| 24 |
# Function to convert speech to text
|
| 25 |
+
|
| 26 |
def speech_to_text(audio):
|
| 27 |
+
model = whisper.load_model("base") # Or any model size you prefer
|
| 28 |
+
result = model.transcribe(audio.name) # Use the audio file
|
| 29 |
+
return result['text']
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Chatbot function
|
| 33 |
def chatbot(user_input, history=[]):
|