Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
from io import BytesIO
|
| 3 |
import gradio as gr
|
| 4 |
from gtts import gTTS
|
| 5 |
from pydub import AudioSegment
|
| 6 |
import whisper
|
| 7 |
-
import openai
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
# Initialize models
|
| 14 |
whisper_model = whisper.load_model("base") # Load Whisper model
|
|
@@ -19,7 +20,7 @@ def voice_to_voice(audio):
|
|
| 19 |
transcription_result = whisper_model.transcribe(audio, fp16=False)
|
| 20 |
user_input = transcription_result["text"]
|
| 21 |
|
| 22 |
-
# 2. Get response from OpenAI's GPT
|
| 23 |
response = openai.ChatCompletion.create(
|
| 24 |
model="gpt-4",
|
| 25 |
messages=[{"role": "user", "content": user_input}],
|
|
@@ -43,7 +44,7 @@ def voice_to_voice(audio):
|
|
| 43 |
# Gradio interface
|
| 44 |
iface = gr.Interface(
|
| 45 |
fn=voice_to_voice,
|
| 46 |
-
inputs=gr.Audio(type="filepath"),
|
| 47 |
outputs=[gr.Textbox(label="Transcription"), gr.Audio(label="Response Audio")],
|
| 48 |
live=True,
|
| 49 |
title="Real-Time Voice-to-Voice Chatbot",
|
|
@@ -51,4 +52,5 @@ iface = gr.Interface(
|
|
| 51 |
)
|
| 52 |
|
| 53 |
# Launch Gradio app
|
| 54 |
-
|
|
|
|
|
|
| 1 |
+
# Install required libraries
|
| 2 |
import os
|
| 3 |
from io import BytesIO
|
| 4 |
import gradio as gr
|
| 5 |
from gtts import gTTS
|
| 6 |
from pydub import AudioSegment
|
| 7 |
import whisper
|
| 8 |
+
import openai
|
| 9 |
|
| 10 |
+
# Set up OpenAI API key
|
| 11 |
+
os.environ["OPENAI_API_KEY"] = "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"
|
| 12 |
+
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 13 |
|
| 14 |
# Initialize models
|
| 15 |
whisper_model = whisper.load_model("base") # Load Whisper model
|
|
|
|
| 20 |
transcription_result = whisper_model.transcribe(audio, fp16=False)
|
| 21 |
user_input = transcription_result["text"]
|
| 22 |
|
| 23 |
+
# 2. Get response from OpenAI's GPT
|
| 24 |
response = openai.ChatCompletion.create(
|
| 25 |
model="gpt-4",
|
| 26 |
messages=[{"role": "user", "content": user_input}],
|
|
|
|
| 44 |
# Gradio interface
|
| 45 |
iface = gr.Interface(
|
| 46 |
fn=voice_to_voice,
|
| 47 |
+
inputs=gr.Audio(type="filepath"),
|
| 48 |
outputs=[gr.Textbox(label="Transcription"), gr.Audio(label="Response Audio")],
|
| 49 |
live=True,
|
| 50 |
title="Real-Time Voice-to-Voice Chatbot",
|
|
|
|
| 52 |
)
|
| 53 |
|
| 54 |
# Launch Gradio app
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
iface.launch()
|