Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ import io
|
|
| 12 |
import speech_recognition as sr
|
| 13 |
from gtts import gTTS
|
| 14 |
import os
|
| 15 |
-
|
| 16 |
|
| 17 |
|
| 18 |
# Download NLTK resources
|
|
@@ -106,6 +106,32 @@ st.markdown("""
|
|
| 106 |
</style>
|
| 107 |
""", unsafe_allow_html=True)
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
# App title and description
|
| 110 |
st.title("π° Daily Mirror News Analyzer")
|
| 111 |
st.markdown("""
|
|
@@ -183,9 +209,11 @@ with tab2:
|
|
| 183 |
st.warning("Please upload a CSV file.")
|
| 184 |
|
| 185 |
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
|
|
|
|
|
|
| 189 |
|
| 190 |
|
| 191 |
|
|
@@ -202,30 +230,6 @@ with tab2:
|
|
| 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 |
|
| 231 |
with tab3:
|
|
|
|
| 12 |
import speech_recognition as sr
|
| 13 |
from gtts import gTTS
|
| 14 |
import os
|
| 15 |
+
|
| 16 |
|
| 17 |
|
| 18 |
# Download NLTK resources
|
|
|
|
| 106 |
</style>
|
| 107 |
""", unsafe_allow_html=True)
|
| 108 |
|
| 109 |
+
st.markdown("""
|
| 110 |
+
<script>
|
| 111 |
+
function startRecording() {
|
| 112 |
+
var recognition = new webkitSpeechRecognition() || new SpeechRecognition();
|
| 113 |
+
recognition.lang = 'en-US';
|
| 114 |
+
recognition.interimResults = false;
|
| 115 |
+
recognition.maxAlternatives = 1;
|
| 116 |
+
|
| 117 |
+
recognition.onresult = function(event) {
|
| 118 |
+
var transcript = event.results[0][0].transcript;
|
| 119 |
+
var questionInput = document.getElementById("question_input");
|
| 120 |
+
questionInput.value = transcript;
|
| 121 |
+
questionInput.dispatchEvent(new Event('input', { bubbles: true }));
|
| 122 |
+
};
|
| 123 |
+
|
| 124 |
+
recognition.onerror = function(event) {
|
| 125 |
+
alert("Error occurred: " + event.error);
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
recognition.start();
|
| 129 |
+
}
|
| 130 |
+
</script>
|
| 131 |
+
""", unsafe_allow_html=True)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
# App title and description
|
| 136 |
st.title("π° Daily Mirror News Analyzer")
|
| 137 |
st.markdown("""
|
|
|
|
| 209 |
st.warning("Please upload a CSV file.")
|
| 210 |
|
| 211 |
|
| 212 |
+
# Input field for voice/text-based questions
|
| 213 |
+
question = st.text_input("Enter your question:", key="question_input")
|
| 214 |
+
|
| 215 |
+
# Button to start voice recording
|
| 216 |
+
st.button("π Speak", on_click=lambda: st.markdown('<script>startRecording()</script>', unsafe_allow_html=True))
|
| 217 |
|
| 218 |
|
| 219 |
|
|
|
|
| 230 |
|
| 231 |
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
|
| 234 |
|
| 235 |
with tab3:
|