Spaces:
Runtime error
Runtime error
app1
Browse files
app.py
CHANGED
@@ -121,7 +121,6 @@ qa_chain = ConversationalRetrievalChain.from_llm(
|
|
121 |
|
122 |
import numpy as np
|
123 |
import soundfile as sf
|
124 |
-
|
125 |
# Load ASR pipeline
|
126 |
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-large")
|
127 |
|
@@ -145,14 +144,32 @@ def chat_interface(question, audio_input=None, history=None):
|
|
145 |
# Transcribe the audio input
|
146 |
question = transcribe(audio_input)
|
147 |
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
chatbot_gradio_app = gr.Interface(
|
152 |
fn=chat_interface,
|
153 |
inputs=[
|
154 |
gr.Textbox(lines=3, label="Type your message here"),
|
155 |
-
gr.Audio(label="Record your voice", type='numpy')
|
156 |
],
|
157 |
outputs=gr.Textbox(label="Bot's Response"),
|
158 |
)
|
|
|
121 |
|
122 |
import numpy as np
|
123 |
import soundfile as sf
|
|
|
124 |
# Load ASR pipeline
|
125 |
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-large")
|
126 |
|
|
|
144 |
# Transcribe the audio input
|
145 |
question = transcribe(audio_input)
|
146 |
|
147 |
+
|
148 |
+
return question
|
149 |
+
|
150 |
+
# Original chatbot logic
|
151 |
+
result = qa_chain.invoke({'question': question})
|
152 |
+
output_string = result['output']
|
153 |
+
|
154 |
+
# Find the index of the last occurrence of "answer": in the string
|
155 |
+
answer_index = output_string.rfind('"answer":')
|
156 |
+
|
157 |
+
# Extract the substring starting from the "answer": index
|
158 |
+
answer_part = output_string[answer_index + len('"answer":'):].strip()
|
159 |
+
|
160 |
+
# Find the next occurrence of a double quote to get the start of the answer value
|
161 |
+
quote_index = answer_part.find('"')
|
162 |
+
|
163 |
+
# Extract the answer value between double quotes
|
164 |
+
answer_value = answer_part[quote_index + 1:answer_part.find('"', quote_index + 1)]
|
165 |
+
|
166 |
+
return answer_value
|
167 |
|
168 |
chatbot_gradio_app = gr.Interface(
|
169 |
fn=chat_interface,
|
170 |
inputs=[
|
171 |
gr.Textbox(lines=3, label="Type your message here"),
|
172 |
+
gr.Audio(label="Record your voice", type='numpy') # Change type to "microphone"
|
173 |
],
|
174 |
outputs=gr.Textbox(label="Bot's Response"),
|
175 |
)
|