Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -184,11 +184,10 @@ with tab2:
|
|
| 184 |
|
| 185 |
|
| 186 |
question = st.text_input("Enter your question:")
|
| 187 |
-
use_voice = False
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
|
| 193 |
if st.button("Get Answer") and context and question:
|
| 194 |
with st.spinner("Searching for answers..."):
|
|
@@ -201,17 +200,30 @@ with tab2:
|
|
| 201 |
st.subheader("Details")
|
| 202 |
st.write(f"Confidence: {result['score']:.2f}")
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
|
| 210 |
-
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
|
| 217 |
with tab3:
|
|
|
|
| 184 |
|
| 185 |
|
| 186 |
question = st.text_input("Enter your question:")
|
|
|
|
| 187 |
|
| 188 |
+
recognizer = sr.Recognizer()
|
| 189 |
+
|
| 190 |
+
|
| 191 |
|
| 192 |
if st.button("Get Answer") and context and question:
|
| 193 |
with st.spinner("Searching for answers..."):
|
|
|
|
| 200 |
st.subheader("Details")
|
| 201 |
st.write(f"Confidence: {result['score']:.2f}")
|
| 202 |
|
| 203 |
+
if st.button("🎤 Ask Question via Mic"):
|
| 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 |
+
except sr.UnknownValueError:
|
| 223 |
+
st.error("Sorry, could not understand the question. Please try again.")
|
| 224 |
+
except sr.RequestError:
|
| 225 |
+
st.error("Speech Recognition API is unavailable.")
|
| 226 |
+
|
| 227 |
|
| 228 |
|
| 229 |
with tab3:
|