Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import openai
|
3 |
-
import speech_recognition as sr
|
4 |
-
|
5 |
-
# Set your OpenAI API key here
|
6 |
-
openai.api_key = "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"
|
7 |
-
|
8 |
-
def speech_to_text(audio):
|
9 |
-
recognizer = sr.Recognizer()
|
10 |
-
with sr.AudioFile(audio.name) as source:
|
11 |
-
audio_data = recognizer.record(source)
|
12 |
-
try:
|
13 |
-
text = recognizer.recognize_google(audio_data)
|
14 |
-
return text
|
15 |
-
except sr.UnknownValueError:
|
16 |
-
return "Sorry, I could not understand the audio."
|
17 |
-
except sr.RequestError:
|
18 |
-
return "Could not request results from Google Speech Recognition service."
|
19 |
-
|
20 |
-
def text_to_ai_response(text):
|
21 |
-
response = openai.Completion.create(
|
22 |
-
engine="text-davinci-003",
|
23 |
-
prompt=text,
|
24 |
-
max_tokens=200
|
25 |
-
)
|
26 |
-
return response.choices[0].text.strip()
|
27 |
-
|
28 |
-
# Interface for Gradio
|
29 |
-
interface = gr.Interface(
|
30 |
-
fn=lambda audio: text_to_ai_response(speech_to_text(audio)),
|
31 |
-
inputs="audio", # Correct input type
|
32 |
-
outputs="text", # Correct output type
|
33 |
-
title="Voice AI Agent",
|
34 |
-
description="An AI-powered voice assistant powered by OpenAI and Gradio."
|
35 |
-
)
|
36 |
-
|
37 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|