Spaces:
Running
Running
Safwanahmad619
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,173 +1,3 @@
|
|
1 |
-
# import os
|
2 |
-
# import gradio as gr
|
3 |
-
# import whisper
|
4 |
-
# from gtts import gTTS
|
5 |
-
# import io
|
6 |
-
# from groq import Groq
|
7 |
-
|
8 |
-
# # Initialize the Groq client
|
9 |
-
# groq_api_key = os.getenv('GROQ_API_KEY')
|
10 |
-
# client = Groq(api_key=groq_api_key)
|
11 |
-
|
12 |
-
# # Load the Whisper model
|
13 |
-
# model = whisper.load_model("base") # You can choose other models like "small", "medium", "large"
|
14 |
-
|
15 |
-
# def process_audio(file_path):
|
16 |
-
# try:
|
17 |
-
# # Load the audio file
|
18 |
-
# audio = whisper.load_audio(file_path)
|
19 |
-
|
20 |
-
# # Transcribe the audio using Whisper
|
21 |
-
# result = model.transcribe(audio)
|
22 |
-
# text = result["text"]
|
23 |
-
|
24 |
-
# # Generate a response using Groq
|
25 |
-
# chat_completion = client.chat.completions.create(
|
26 |
-
# messages=[{"role": "user", "content": text}],
|
27 |
-
# model="llama3-8b-8192", # Replace with the correct model if necessary
|
28 |
-
# )
|
29 |
-
|
30 |
-
# # Access the response using dot notation
|
31 |
-
# response_message = chat_completion.choices[0].message.content.strip()
|
32 |
-
|
33 |
-
# # Convert the response text to speech
|
34 |
-
# tts = gTTS(response_message)
|
35 |
-
# response_audio_io = io.BytesIO()
|
36 |
-
# tts.write_to_fp(response_audio_io) # Save the audio to the BytesIO object
|
37 |
-
# response_audio_io.seek(0)
|
38 |
-
|
39 |
-
# # Save audio to a file to ensure it's generated correctly
|
40 |
-
# with open("response.mp3", "wb") as audio_file:
|
41 |
-
# audio_file.write(response_audio_io.getvalue())
|
42 |
-
|
43 |
-
# # Return the response text and the path to the saved audio file
|
44 |
-
# return response_message, "response.mp3"
|
45 |
-
|
46 |
-
# except Exception as e:
|
47 |
-
# return f"An error occurred: {e}", None
|
48 |
-
|
49 |
-
# iface = gr.Interface(
|
50 |
-
# fn=process_audio,
|
51 |
-
# inputs=gr.Audio(type="filepath"), # Use type="filepath"
|
52 |
-
# outputs=[gr.Textbox(label="Response Text"), gr.Audio(label="Response Audio")],
|
53 |
-
# live=True
|
54 |
-
# )
|
55 |
-
|
56 |
-
# # iface.launch()
|
57 |
-
# import os
|
58 |
-
# import gradio as gr
|
59 |
-
# import whisper
|
60 |
-
# from gtts import gTTS
|
61 |
-
# from anthropic import Anthropic # Import the Anthropic client
|
62 |
-
# import io # Import io for BytesIO
|
63 |
-
|
64 |
-
# # Get the Anthropic API key from environment variables
|
65 |
-
# ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY")
|
66 |
-
# if not ANTHROPIC_API_KEY:
|
67 |
-
# raise ValueError("ANTHROPIC_API_KEY environment variable is not set.")
|
68 |
-
# client = Anthropic(api_key=ANTHROPIC_API_KEY) # Initialize the Anthropic client
|
69 |
-
|
70 |
-
# # Load Whisper model
|
71 |
-
# model = whisper.load_model("base") # You can also use "small", "medium", "large"
|
72 |
-
|
73 |
-
# def chatbot(audio=None):
|
74 |
-
# try:
|
75 |
-
# if audio is None:
|
76 |
-
# return "No input detected. Please provide an audio input.", None
|
77 |
-
|
78 |
-
# # Transcribe the audio input using Whisper
|
79 |
-
# transcription = model.transcribe(audio)
|
80 |
-
# user_input = transcription.get("text", "")
|
81 |
-
|
82 |
-
# # Generate a response using Anthropic API
|
83 |
-
# chat_completion = client.completions.create(
|
84 |
-
# model="claude-v1", # Specify the model
|
85 |
-
# prompt=user_input, # Provide the user input as the prompt
|
86 |
-
# max_tokens_to_sample=100, # Specify the maximum tokens to sample
|
87 |
-
# )
|
88 |
-
# response_text = chat_completion['completion']
|
89 |
-
|
90 |
-
# # Convert the response text to speech using gTTS
|
91 |
-
# tts = gTTS(text=response_text, lang='en')
|
92 |
-
# response_audio_io = io.BytesIO() # Create a BytesIO object
|
93 |
-
# tts.save(response_audio_io) # Save the audio to the BytesIO object
|
94 |
-
# response_audio_io.seek(0) # Rewind the BytesIO object
|
95 |
-
|
96 |
-
# return response_text, response_audio_io
|
97 |
-
|
98 |
-
# except Exception as e:
|
99 |
-
# return f"An error occurred: {e}", None
|
100 |
-
|
101 |
-
# def clear_inputs():
|
102 |
-
# return None, None, None
|
103 |
-
|
104 |
-
# # Create a custom interface
|
105 |
-
# def build_interface():
|
106 |
-
# with gr.Blocks(css="""
|
107 |
-
# .block-title {
|
108 |
-
# text-align: center;
|
109 |
-
# color: white;
|
110 |
-
# background-color: #4CAF50;
|
111 |
-
# padding: 10px;
|
112 |
-
# border-radius: 8px;
|
113 |
-
# }
|
114 |
-
# .gradio-row {
|
115 |
-
# background-color: #f9f9f9;
|
116 |
-
# border-radius: 8px;
|
117 |
-
# padding: 20px;
|
118 |
-
# margin: 10px;
|
119 |
-
# box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);
|
120 |
-
# }
|
121 |
-
# .gradio-column {
|
122 |
-
# padding: 10px;
|
123 |
-
# }
|
124 |
-
# .gradio-button {
|
125 |
-
# background-color: #ff6347 !important;
|
126 |
-
# color: white !important;
|
127 |
-
# border-radius: 8px !important;
|
128 |
-
# padding: 10px 20px !important;
|
129 |
-
# font-size: 16px !important;
|
130 |
-
# border: none !important;
|
131 |
-
# cursor: pointer !important;
|
132 |
-
# box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.2) !important;
|
133 |
-
# transition: background-color 0.3s ease !important;
|
134 |
-
# }
|
135 |
-
# .gradio-button:hover {
|
136 |
-
# background-color: #e5533d !important;
|
137 |
-
# }
|
138 |
-
# """) as demo:
|
139 |
-
# gr.Markdown(
|
140 |
-
# """
|
141 |
-
# <h1 class="block-title">Voice-to-Voice AI Chatbot</h1>
|
142 |
-
# """
|
143 |
-
# )
|
144 |
-
# with gr.Row(elem_classes="gradio-row"):
|
145 |
-
# with gr.Column(elem_classes="gradio-column", scale=1):
|
146 |
-
# audio_input = gr.Audio(type="filepath", label="Record Your Voice")
|
147 |
-
# with gr.Column(elem_classes="gradio-column", scale=2):
|
148 |
-
# chatbot_output_text = gr.Textbox(label="Chatbot Response")
|
149 |
-
# chatbot_output_audio = gr.Audio(label="Audio Response")
|
150 |
-
|
151 |
-
# clear_button = gr.Button("Clear", elem_classes="gradio-button")
|
152 |
-
|
153 |
-
# clear_button.click(
|
154 |
-
# fn=clear_inputs,
|
155 |
-
# outputs=[audio_input, chatbot_output_text, chatbot_output_audio]
|
156 |
-
# )
|
157 |
-
|
158 |
-
# audio_input.change(
|
159 |
-
# fn=chatbot,
|
160 |
-
# inputs=[audio_input],
|
161 |
-
# outputs=[chatbot_output_text, chatbot_output_audio]
|
162 |
-
# )
|
163 |
-
|
164 |
-
# return demo
|
165 |
-
|
166 |
-
# # Launch the interface
|
167 |
-
# if __name__ == "__main__":
|
168 |
-
# interface = build_interface()
|
169 |
-
# interface.launch()
|
170 |
-
|
171 |
import gradio as gr
|
172 |
import whisper
|
173 |
from gtts import gTTS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import whisper
|
3 |
from gtts import gTTS
|