Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -200,29 +200,31 @@ with tab2:
|
|
| 200 |
st.subheader("Details")
|
| 201 |
st.write(f"Confidence: {result['score']:.2f}")
|
| 202 |
|
| 203 |
-
|
| 204 |
-
with sr.Microphone() as source:
|
| 205 |
-
st.info("Listening...")
|
| 206 |
-
try:
|
| 207 |
-
audio = recognizer.listen(source, timeout=5)
|
| 208 |
-
question = recognizer.recognize_google(audio)
|
| 209 |
-
st.success(f"Question: {question}")
|
| 210 |
-
|
| 211 |
-
if uploaded_file is not None:
|
| 212 |
-
context = ' '.join(df['content'].tolist()) # Extracted from uploaded news data
|
| 213 |
-
qa_pipeline = load_qa_model()
|
| 214 |
-
result = qa_pipeline(question=question, context=context)
|
| 215 |
-
|
| 216 |
-
st.subheader("📝 Answer")
|
| 217 |
-
st.success(result['answer'])
|
| 218 |
-
st.write(f"Confidence: {result['score']:.2f}")
|
| 219 |
-
else:
|
| 220 |
-
st.warning("Please upload a CSV file first.")
|
| 221 |
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
|
| 228 |
|
|
|
|
| 200 |
st.subheader("Details")
|
| 201 |
st.write(f"Confidence: {result['score']:.2f}")
|
| 202 |
|
| 203 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
+
if st.button("🎤 Ask Question via Mic"):
|
| 206 |
+
with sr.Microphone() as source:
|
| 207 |
+
st.info("Listening...")
|
| 208 |
+
try:
|
| 209 |
+
audio = recognizer.listen(source, timeout=5)
|
| 210 |
+
question = recognizer.recognize_google(audio)
|
| 211 |
+
st.success(f"Question: {question}")
|
| 212 |
+
|
| 213 |
+
if uploaded_file is not None:
|
| 214 |
+
context = ' '.join(df['content'].tolist()) # Extracted from uploaded news data
|
| 215 |
+
qa_pipeline = load_qa_model()
|
| 216 |
+
result = qa_pipeline(question=question, context=context)
|
| 217 |
+
|
| 218 |
+
st.subheader("📝 Answer")
|
| 219 |
+
st.success(result['answer'])
|
| 220 |
+
st.write(f"Confidence: {result['score']:.2f}")
|
| 221 |
+
else:
|
| 222 |
+
st.warning("Please upload a CSV file first.")
|
| 223 |
+
|
| 224 |
+
except sr.UnknownValueError:
|
| 225 |
+
st.error("Sorry, could not understand the question. Please try again.")
|
| 226 |
+
except sr.RequestError:
|
| 227 |
+
st.error("Speech Recognition API is unavailable.")
|
| 228 |
|
| 229 |
|
| 230 |
|