Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -40,6 +40,35 @@ def extract_article_content(url):
|
|
40 |
except Exception as e:
|
41 |
return ""
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
|
45 |
@app.post("/summarize-v2")
|
|
|
40 |
except Exception as e:
|
41 |
return ""
|
42 |
|
43 |
+
@app.post("/summarize-v1")
|
44 |
+
async def root(item: Item):
|
45 |
+
|
46 |
+
try:
|
47 |
+
|
48 |
+
article = extract_article_content(item.url)
|
49 |
+
|
50 |
+
if len(article) == 0:
|
51 |
+
return {'summary': ""}
|
52 |
+
|
53 |
+
response = requests.post('https://fumes-api.onrender.com/llama3',
|
54 |
+
json={'prompt': "{ 'User': 'Summarize the following news article: '" + article + "}",
|
55 |
+
"temperature":0.6,
|
56 |
+
"topP":0.9,
|
57 |
+
"maxTokens": 200}, stream=False)
|
58 |
+
|
59 |
+
response_content = response.content.decode('utf-8')
|
60 |
+
|
61 |
+
response_content = response_content.replace("Here is a summary of the news article:", "")
|
62 |
+
response_content = response_content.replace("YOU CAN BUY ME COFFE! https://buymeacoffee.com/mygx", "")
|
63 |
+
|
64 |
+
|
65 |
+
return {"summary":response_content}
|
66 |
+
|
67 |
+
except requests.RequestException as e:
|
68 |
+
return {"error": str(e), "status_code": 500}
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
|
73 |
|
74 |
@app.post("/summarize-v2")
|