Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,11 +9,6 @@ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassifica
|
|
| 9 |
from wordcloud import WordCloud
|
| 10 |
import matplotlib.pyplot as plt
|
| 11 |
import io
|
| 12 |
-
import speech_recognition as sr
|
| 13 |
-
from gtts import gTTS
|
| 14 |
-
import os
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
# Download NLTK resources
|
| 19 |
nltk.download('punkt')
|
|
@@ -35,22 +30,6 @@ def load_classification_model():
|
|
| 35 |
def load_qa_model():
|
| 36 |
return pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 37 |
|
| 38 |
-
def recognize_speech():
|
| 39 |
-
recognizer = sr.Recognizer()
|
| 40 |
-
with sr.Microphone() as source:
|
| 41 |
-
st.info("Listening... Speak now.")
|
| 42 |
-
try:
|
| 43 |
-
audio = recognizer.listen(source, timeout=5) # Listen for 5 seconds
|
| 44 |
-
question_text = recognizer.recognize_google(audio) # Convert speech to text
|
| 45 |
-
st.success(f"You said: {question_text}") # Show recognized text
|
| 46 |
-
return question_text
|
| 47 |
-
except sr.UnknownValueError:
|
| 48 |
-
st.error("Sorry, could not understand the audio.")
|
| 49 |
-
except sr.RequestError:
|
| 50 |
-
st.error("Could not request results, check your internet connection.")
|
| 51 |
-
return Non
|
| 52 |
-
|
| 53 |
-
|
| 54 |
# Preprocessing function (same as in Section 01)
|
| 55 |
def preprocess_text(text):
|
| 56 |
# Lowercase
|
|
@@ -106,32 +85,6 @@ st.markdown("""
|
|
| 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,13 +162,7 @@ with tab2:
|
|
| 209 |
st.warning("Please upload a CSV file.")
|
| 210 |
|
| 211 |
|
| 212 |
-
|
| 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 |
|
| 220 |
if st.button("Get Answer") and context and question:
|
| 221 |
with st.spinner("Searching for answers..."):
|
|
@@ -227,9 +174,6 @@ with tab2:
|
|
| 227 |
|
| 228 |
st.subheader("Details")
|
| 229 |
st.write(f"Confidence: {result['score']:.2f}")
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
|
| 234 |
|
| 235 |
with tab3:
|
|
@@ -251,7 +195,7 @@ with tab3:
|
|
| 251 |
st.warning("This text appears negative.")
|
| 252 |
|
| 253 |
# Named Entity Recognition
|
| 254 |
-
st.subheader("🏷
|
| 255 |
ner_text = st.text_area("Enter text for entity recognition:", height=100)
|
| 256 |
if st.button("Extract Entities"):
|
| 257 |
with st.spinner("Identifying entities..."):
|
|
@@ -269,7 +213,7 @@ with tab3:
|
|
| 269 |
st.table(pd.DataFrame(entities))
|
| 270 |
|
| 271 |
# Text Summarization
|
| 272 |
-
st.subheader("✍
|
| 273 |
summary_text = st.text_area("Enter text to summarize:", height=150)
|
| 274 |
if st.button("Generate Summary"):
|
| 275 |
with st.spinner("Generating summary..."):
|
|
|
|
| 9 |
from wordcloud import WordCloud
|
| 10 |
import matplotlib.pyplot as plt
|
| 11 |
import io
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Download NLTK resources
|
| 14 |
nltk.download('punkt')
|
|
|
|
| 30 |
def load_qa_model():
|
| 31 |
return pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# Preprocessing function (same as in Section 01)
|
| 34 |
def preprocess_text(text):
|
| 35 |
# Lowercase
|
|
|
|
| 85 |
</style>
|
| 86 |
""", unsafe_allow_html=True)
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
# App title and description
|
| 89 |
st.title("📰 Daily Mirror News Analyzer")
|
| 90 |
st.markdown("""
|
|
|
|
| 162 |
st.warning("Please upload a CSV file.")
|
| 163 |
|
| 164 |
|
| 165 |
+
question = st.text_input("Enter your question:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
if st.button("Get Answer") and context and question:
|
| 168 |
with st.spinner("Searching for answers..."):
|
|
|
|
| 174 |
|
| 175 |
st.subheader("Details")
|
| 176 |
st.write(f"Confidence: {result['score']:.2f}")
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
|
| 179 |
with tab3:
|
|
|
|
| 195 |
st.warning("This text appears negative.")
|
| 196 |
|
| 197 |
# Named Entity Recognition
|
| 198 |
+
st.subheader("🏷 Named Entity Recognition")
|
| 199 |
ner_text = st.text_area("Enter text for entity recognition:", height=100)
|
| 200 |
if st.button("Extract Entities"):
|
| 201 |
with st.spinner("Identifying entities..."):
|
|
|
|
| 213 |
st.table(pd.DataFrame(entities))
|
| 214 |
|
| 215 |
# Text Summarization
|
| 216 |
+
st.subheader("✍ Text Summarization")
|
| 217 |
summary_text = st.text_area("Enter text to summarize:", height=150)
|
| 218 |
if st.button("Generate Summary"):
|
| 219 |
with st.spinner("Generating summary..."):
|