Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -36,41 +36,7 @@ def extract_article_content(url):
|
|
36 |
return ""
|
37 |
|
38 |
|
39 |
-
@app.post("/summarize-v1")
|
40 |
-
async def root(item: Item):
|
41 |
-
|
42 |
-
try:
|
43 |
-
|
44 |
-
article = extract_article_content(item.url)
|
45 |
-
|
46 |
-
url = "https://text-analysis12.p.rapidapi.com/summarize-text/api/v1.1"
|
47 |
-
|
48 |
-
payload = {
|
49 |
-
"language": "english",
|
50 |
-
"summary_percent": item.percentage,
|
51 |
-
'text': article
|
52 |
-
}
|
53 |
-
headers = {
|
54 |
-
"content-type": "application/json",
|
55 |
-
"X-RapidAPI-Key":"836bb8ca1fmsh79ad9dd5bf8734fp1460bejsn5eac87118b33",
|
56 |
-
"X-RapidAPI-Host": "text-analysis12.p.rapidapi.com"
|
57 |
-
}
|
58 |
-
|
59 |
-
response = requests.post(url, json=payload, headers=headers).json()
|
60 |
-
|
61 |
|
62 |
-
#text processing
|
63 |
-
text = response["summary"].replace('\"', " ");
|
64 |
-
text = re.sub(r'\s+', ' ', text)
|
65 |
-
|
66 |
-
|
67 |
-
#return {clean_response}
|
68 |
-
return {
|
69 |
-
"summary":text}
|
70 |
-
|
71 |
-
except requests.RequestException as e:
|
72 |
-
return {"error": str(e), "status_code": 500}
|
73 |
-
|
74 |
@app.post("/summarize-v2")
|
75 |
async def root(item: Item):
|
76 |
|
@@ -81,7 +47,7 @@ async def root(item: Item):
|
|
81 |
if len(article) == 0:
|
82 |
return {'summary': ""}
|
83 |
response = requests.post('https://fumes-api.onrender.com/llama3',
|
84 |
-
json={'prompt': "{ 'User': 'Summarize the following news article
|
85 |
"temperature":0.6,
|
86 |
"topP":0.9,
|
87 |
"maxTokens": 200}, stream=True)
|
|
|
36 |
return ""
|
37 |
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
@app.post("/summarize-v2")
|
41 |
async def root(item: Item):
|
42 |
|
|
|
47 |
if len(article) == 0:
|
48 |
return {'summary': ""}
|
49 |
response = requests.post('https://fumes-api.onrender.com/llama3',
|
50 |
+
json={'prompt': "{ 'User': 'Summarize the following news article: '" + article + "}",
|
51 |
"temperature":0.6,
|
52 |
"topP":0.9,
|
53 |
"maxTokens": 200}, stream=True)
|