Spaces:
Running
Running
Jeff Myers II
commited on
Commit
·
1d0b89a
1
Parent(s):
5c92ada
Update space
Browse files- app.py +53 -53
- requirements.txt +6 -1
app.py
CHANGED
@@ -1,64 +1,64 @@
|
|
1 |
-
import
|
2 |
-
from
|
|
|
|
|
3 |
|
4 |
-
""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
history: list[tuple[str, str]],
|
13 |
-
system_message,
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
-
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
|
21 |
-
if val[0]:
|
22 |
-
messages.append({"role": "user", "content": val[0]})
|
23 |
-
if val[1]:
|
24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
token = message.choices[0].delta.content
|
38 |
|
39 |
-
|
40 |
-
yield response
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
-
demo = gr.ChatInterface(
|
47 |
-
respond,
|
48 |
-
additional_inputs=[
|
49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
-
gr.Slider(
|
53 |
-
minimum=0.1,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
-
],
|
60 |
-
)
|
61 |
|
62 |
-
|
63 |
-
if __name__ == "__main__":
|
64 |
-
demo.launch()
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from flask_cors import CORS
|
3 |
+
from News import News
|
4 |
+
from Gemma_Model import GemmaLLM
|
5 |
|
6 |
+
print("Starting server...")
|
|
|
|
|
|
|
7 |
|
8 |
+
app = Flask(__name__)
|
9 |
+
CORS(app)
|
10 |
|
11 |
+
news = News()
|
12 |
+
gemma = GemmaLLM()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
# business entertainment general health science sports technology
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
@app.get("/get_top_articles/")
|
17 |
+
@app.get("/get_top_articles/<string:category>/")
|
18 |
+
@app.get("/get_top_articles/<int:num_articles>/")
|
19 |
+
@app.get("/get_top_articles/<int:num_articles>/<string:category>/")
|
20 |
+
def get_top_articles(num_articles=5, category=None):
|
21 |
+
if category is not None: category = category.lower()
|
22 |
+
articles = news.get_top_headlines(num_headlines=num_articles, category=category)
|
23 |
+
articles = news.get_articles_from_headlines(articles)
|
24 |
+
|
25 |
+
return jsonify(articles)
|
26 |
|
27 |
+
@app.get("/get_articles/")
|
28 |
+
@app.get("/get_articles/<string:query>/")
|
29 |
+
@app.get("/get_articles/<int:num_articles>/")
|
30 |
+
@app.get("/get_articles/<int:num_articles>/<string:query>/")
|
31 |
+
def get_articles(num_articles=5, query=None):
|
32 |
+
if query is not None: query = query.lower()
|
33 |
+
articles = news.get_headlines(num_headlines=num_articles, query=query)
|
34 |
+
articles = news.get_articles_from_headlines(articles)
|
35 |
+
|
36 |
+
return jsonify(articles)
|
37 |
|
38 |
+
@app.post("/get_summary/")
|
39 |
+
@app.post("/get_summary/<int:num_paragraphs>/")
|
40 |
+
def get_summary(num_paragraphs=1):
|
41 |
+
article = request.json
|
42 |
+
message = gemma.get_summary_message(article, num_paragraphs)
|
43 |
+
summary = gemma.get_summary(message)
|
44 |
+
article["summary"] = summary
|
|
|
45 |
|
46 |
+
return jsonify(article)
|
|
|
47 |
|
48 |
+
@app.post("/get_questions/")
|
49 |
+
@app.post("/get_questions/<string:difficulty>/")
|
50 |
+
@app.post("/get_questions/<int:num_questions>/")
|
51 |
+
@app.post("/get_questions/<int:num_questions>/<string:difficulty>/")
|
52 |
+
def get_questions(num_questions=3, difficulty="average"):
|
53 |
+
if "summary" in request.json:
|
54 |
+
summary = request.json["summary"]
|
55 |
+
questions = gemma.get_questions(gemma.get_questions_message(summary, num_questions, difficulty))
|
56 |
+
elif "summaries" in request.json:
|
57 |
+
summaries = request.json["summaries"]
|
58 |
+
messages = [gemma.get_questions_message(summary) for summary in summaries]
|
59 |
+
questions = gemma.get_questions(messages)
|
60 |
+
else: return jsonify({})
|
61 |
|
62 |
+
return jsonify(questions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
+
if __name__ == "__main__": app.run()
|
|
|
|
requirements.txt
CHANGED
@@ -1 +1,6 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Flask==3.1.0
|
2 |
+
flask_cors==5.0.1
|
3 |
+
newsapi_python==0.2.7
|
4 |
+
newspaper3k==0.2.8
|
5 |
+
torch==2.6.0+cu118
|
6 |
+
transformers==4.50.0.dev0
|