Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -81,11 +81,33 @@ st.markdown("""
|
|
| 81 |
background-color: #ffffff;
|
| 82 |
color : #FF6347;
|
| 83 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
</style>
|
| 85 |
""", unsafe_allow_html=True)
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
# App title and description
|
| 88 |
-
|
| 89 |
st.markdown("""
|
| 90 |
Analyze news excerpts with our powerful AI tools:
|
| 91 |
- Classify news articles into categories
|
|
@@ -238,29 +260,36 @@ with tab2:
|
|
| 238 |
st.header("Question Answering Pipeline")
|
| 239 |
st.write("Ask questions about news content and get answers from our AI model.")
|
| 240 |
|
| 241 |
-
|
| 242 |
-
|
| 243 |
if uploaded_file is not None:
|
| 244 |
-
|
| 245 |
context = ' '.join(df['content'].tolist()) # Use predictions for Q&A
|
| 246 |
st.write(f"Loaded {len(df)} news excerpts")
|
| 247 |
-
|
| 248 |
else:
|
| 249 |
st.warning("Please upload a CSV file.")
|
| 250 |
-
|
| 251 |
|
|
|
|
| 252 |
question = st.text_input("Enter your question:")
|
| 253 |
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
|
| 266 |
with tab3:
|
|
|
|
| 81 |
background-color: #ffffff;
|
| 82 |
color : #FF6347;
|
| 83 |
}
|
| 84 |
+
|
| 85 |
+
.header {
|
| 86 |
+
display: flex;
|
| 87 |
+
align-items: center;
|
| 88 |
+
margin-bottom: 20px;
|
| 89 |
+
}
|
| 90 |
+
.header img {
|
| 91 |
+
height: 50px; /* Adjust logo size */
|
| 92 |
+
margin-right: 10px;
|
| 93 |
+
}
|
| 94 |
+
.header h3 {
|
| 95 |
+
font-size: 24px;
|
| 96 |
+
color: #4CAF50; /* Adjust the color of the header */
|
| 97 |
+
margin: 0;
|
| 98 |
+
|
| 99 |
</style>
|
| 100 |
""", unsafe_allow_html=True)
|
| 101 |
|
| 102 |
+
st.markdown("""
|
| 103 |
+
<div class="header">
|
| 104 |
+
<img src="https://via.placeholder.com/50x50?text=Logo" alt="Logo">
|
| 105 |
+
<h1>Daily Mirror News Analyzer</h1>
|
| 106 |
+
</div>
|
| 107 |
+
""", unsafe_allow_html=True)
|
| 108 |
+
|
| 109 |
# App title and description
|
| 110 |
+
|
| 111 |
st.markdown("""
|
| 112 |
Analyze news excerpts with our powerful AI tools:
|
| 113 |
- Classify news articles into categories
|
|
|
|
| 260 |
st.header("Question Answering Pipeline")
|
| 261 |
st.write("Ask questions about news content and get answers from our AI model.")
|
| 262 |
|
|
|
|
|
|
|
| 263 |
if uploaded_file is not None:
|
| 264 |
+
# Load the CSV and prepare context for the model
|
| 265 |
context = ' '.join(df['content'].tolist()) # Use predictions for Q&A
|
| 266 |
st.write(f"Loaded {len(df)} news excerpts")
|
|
|
|
| 267 |
else:
|
| 268 |
st.warning("Please upload a CSV file.")
|
|
|
|
| 269 |
|
| 270 |
+
# Input field for the question
|
| 271 |
question = st.text_input("Enter your question:")
|
| 272 |
|
| 273 |
+
# Handle the "Get Answer" button
|
| 274 |
+
if st.button("Get Answer"):
|
| 275 |
+
if uploaded_file is None:
|
| 276 |
+
# Display an error message if no file is uploaded
|
| 277 |
+
st.error("Please upload a CSV file before asking a question.")
|
| 278 |
+
elif context and question:
|
| 279 |
+
# If both a file and a question are provided, answer the question
|
| 280 |
+
with st.spinner("Searching for answers..."):
|
| 281 |
+
qa_pipeline = load_qa_model() # Ensure this function is defined elsewhere
|
| 282 |
+
result = qa_pipeline(question=question, context=context)
|
| 283 |
+
|
| 284 |
+
# Display the answer and details
|
| 285 |
+
st.subheader("Answer")
|
| 286 |
+
st.success(result['answer'])
|
| 287 |
+
|
| 288 |
+
st.subheader("Details")
|
| 289 |
+
st.write(f"Confidence: {result['score']:.2f}")
|
| 290 |
+
else:
|
| 291 |
+
st.error("Please enter a question.")
|
| 292 |
+
|
| 293 |
|
| 294 |
|
| 295 |
with tab3:
|