Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
import os
|
2 |
import feedparser
|
3 |
from flask import Flask, render_template, request
|
4 |
-
from huggingface_hub import HfApi,
|
5 |
-
from langchain_huggingface import HuggingFaceInferenceClient
|
6 |
from langchain.vectorstores import Chroma
|
7 |
from langchain.embeddings import HuggingFaceEmbeddings
|
8 |
from langchain.docstore.document import Document
|
@@ -15,10 +14,11 @@ app = Flask(__name__)
|
|
15 |
# Hugging Face setup
|
16 |
HF_API_TOKEN = os.getenv("HF_API_TOKEN", "YOUR_HF_API_TOKEN")
|
17 |
HF_MODEL = "Qwen/Qwen-72B-Instruct"
|
18 |
-
REPO_ID = "
|
19 |
LOCAL_DB_DIR = "chroma_db"
|
20 |
-
client =
|
21 |
|
|
|
22 |
RSS_FEEDS = [
|
23 |
"https://www.sciencedaily.com/rss/top/science.xml",
|
24 |
"https://www.horoscope.com/us/horoscopes/general/rss/horoscope-rss.aspx",
|
@@ -87,7 +87,6 @@ def fetch_rss_feeds():
|
|
87 |
return articles
|
88 |
|
89 |
def categorize_feed(url):
|
90 |
-
"""Simple categorization based on URL."""
|
91 |
if "sciencedaily" in url or "phys.org" in url:
|
92 |
return "Science & Physics"
|
93 |
elif "horoscope" in url:
|
@@ -103,13 +102,13 @@ def categorize_feed(url):
|
|
103 |
|
104 |
def summarize_article(text):
|
105 |
prompt = f"Summarize the following text concisely:\n\n{text}"
|
106 |
-
response = client.
|
107 |
-
return response.
|
108 |
|
109 |
def categorize_article(text):
|
110 |
prompt = f"Classify the sentiment as positive, negative, or neutral:\n\n{text}"
|
111 |
-
response = client.
|
112 |
-
return response.
|
113 |
|
114 |
def process_and_store_articles(articles):
|
115 |
documents = []
|
@@ -184,7 +183,6 @@ def index():
|
|
184 |
for doc in results
|
185 |
]
|
186 |
|
187 |
-
# Organize by category
|
188 |
categorized_articles = {}
|
189 |
for article in enriched_articles:
|
190 |
cat = article["category"]
|
@@ -194,7 +192,6 @@ def index():
|
|
194 |
|
195 |
return render_template("index.html", categorized_articles=categorized_articles)
|
196 |
|
197 |
-
# Updated HTML template
|
198 |
HTML_TEMPLATE = """
|
199 |
<!DOCTYPE html>
|
200 |
<html lang="en">
|
@@ -304,4 +301,4 @@ if __name__ == "__main__":
|
|
304 |
f.write(HTML_TEMPLATE)
|
305 |
if os.path.exists(LOCAL_DB_DIR):
|
306 |
shutil.rmtree(LOCAL_DB_DIR)
|
307 |
-
app.run(host="0.0.0.0", port=
|
|
|
1 |
import os
|
2 |
import feedparser
|
3 |
from flask import Flask, render_template, request
|
4 |
+
from huggingface_hub import HfApi, InferenceClient
|
|
|
5 |
from langchain.vectorstores import Chroma
|
6 |
from langchain.embeddings import HuggingFaceEmbeddings
|
7 |
from langchain.docstore.document import Document
|
|
|
14 |
# Hugging Face setup
|
15 |
HF_API_TOKEN = os.getenv("HF_API_TOKEN", "YOUR_HF_API_TOKEN")
|
16 |
HF_MODEL = "Qwen/Qwen-72B-Instruct"
|
17 |
+
REPO_ID = "your-username/news-rag-db"
|
18 |
LOCAL_DB_DIR = "chroma_db"
|
19 |
+
client = InferenceClient(model=HF_MODEL, token=HF_API_TOKEN)
|
20 |
|
21 |
+
# Comprehensive RSS feeds
|
22 |
RSS_FEEDS = [
|
23 |
"https://www.sciencedaily.com/rss/top/science.xml",
|
24 |
"https://www.horoscope.com/us/horoscopes/general/rss/horoscope-rss.aspx",
|
|
|
87 |
return articles
|
88 |
|
89 |
def categorize_feed(url):
|
|
|
90 |
if "sciencedaily" in url or "phys.org" in url:
|
91 |
return "Science & Physics"
|
92 |
elif "horoscope" in url:
|
|
|
102 |
|
103 |
def summarize_article(text):
|
104 |
prompt = f"Summarize the following text concisely:\n\n{text}"
|
105 |
+
response = client.text_generation(prompt, max_new_tokens=100, temperature=0.7)
|
106 |
+
return response.strip()
|
107 |
|
108 |
def categorize_article(text):
|
109 |
prompt = f"Classify the sentiment as positive, negative, or neutral:\n\n{text}"
|
110 |
+
response = client.text_generation(prompt, max_new_tokens=10, temperature=0.7)
|
111 |
+
return response.strip()
|
112 |
|
113 |
def process_and_store_articles(articles):
|
114 |
documents = []
|
|
|
183 |
for doc in results
|
184 |
]
|
185 |
|
|
|
186 |
categorized_articles = {}
|
187 |
for article in enriched_articles:
|
188 |
cat = article["category"]
|
|
|
192 |
|
193 |
return render_template("index.html", categorized_articles=categorized_articles)
|
194 |
|
|
|
195 |
HTML_TEMPLATE = """
|
196 |
<!DOCTYPE html>
|
197 |
<html lang="en">
|
|
|
301 |
f.write(HTML_TEMPLATE)
|
302 |
if os.path.exists(LOCAL_DB_DIR):
|
303 |
shutil.rmtree(LOCAL_DB_DIR)
|
304 |
+
app.run(debug=True, host="0.0.0.0", port=5000)
|