Spaces:
Paused
Paused
Shreyas094
commited on
Commit
•
485898b
1
Parent(s):
4d152e0
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import gradio as gr
|
|
5 |
import pandas as pd
|
6 |
import requests
|
7 |
import random
|
|
|
8 |
import urllib.parse
|
9 |
from tempfile import NamedTemporaryFile
|
10 |
from typing import List
|
@@ -277,7 +278,11 @@ def process_google_news_rss(query, temperature, top_p, repetition_penalty):
|
|
277 |
processed_articles.append(processed_article)
|
278 |
|
279 |
# Add processed articles to the database
|
280 |
-
docs = [Document(page_content=article["summary"], metadata={
|
|
|
|
|
|
|
|
|
281 |
|
282 |
if os.path.exists("faiss_database"):
|
283 |
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
@@ -341,13 +346,14 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search, g
|
|
341 |
"""
|
342 |
prompt_val = ChatPromptTemplate.from_template(prompt_template)
|
343 |
formatted_prompt = prompt_val.format(context=context_str, question=question)
|
|
|
344 |
elif google_news_rss:
|
345 |
if database is None:
|
346 |
return "No news articles available. Please fetch news articles first."
|
347 |
|
348 |
retriever = database.as_retriever()
|
349 |
relevant_docs = retriever.get_relevant_documents(question)
|
350 |
-
context_str = "\n".join([f"Title: {doc.metadata
|
351 |
|
352 |
prompt_template = """
|
353 |
Answer the question based on the following news summaries:
|
|
|
5 |
import pandas as pd
|
6 |
import requests
|
7 |
import random
|
8 |
+
import feedparser
|
9 |
import urllib.parse
|
10 |
from tempfile import NamedTemporaryFile
|
11 |
from typing import List
|
|
|
278 |
processed_articles.append(processed_article)
|
279 |
|
280 |
# Add processed articles to the database
|
281 |
+
docs = [Document(page_content=article["summary"], metadata={
|
282 |
+
"source": article["url"],
|
283 |
+
"title": article["title"],
|
284 |
+
"published_date": article["published_date"]
|
285 |
+
}) for article in processed_articles]
|
286 |
|
287 |
if os.path.exists("faiss_database"):
|
288 |
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
|
|
346 |
"""
|
347 |
prompt_val = ChatPromptTemplate.from_template(prompt_template)
|
348 |
formatted_prompt = prompt_val.format(context=context_str, question=question)
|
349 |
+
|
350 |
elif google_news_rss:
|
351 |
if database is None:
|
352 |
return "No news articles available. Please fetch news articles first."
|
353 |
|
354 |
retriever = database.as_retriever()
|
355 |
relevant_docs = retriever.get_relevant_documents(question)
|
356 |
+
context_str = "\n".join([f"Title: {doc.metadata.get('title', 'N/A')}\nURL: {doc.metadata.get('source', 'N/A')}\nSummary: {doc.page_content}" for doc in relevant_docs])
|
357 |
|
358 |
prompt_template = """
|
359 |
Answer the question based on the following news summaries:
|