Spaces:
Running
Running
yash2316
commited on
Commit
·
3a9cb94
1
Parent(s):
de97a2b
Add application file
Browse files- .dockerignore +23 -0
- .gitignore +2 -0
- Dockerfile +11 -0
- __pycache__/main.cpython-312.pyc +0 -0
- app/main.py +96 -0
- requirements.txt +5 -0
.dockerignore
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__pycache__
|
2 |
+
*.pyc
|
3 |
+
*.pyo
|
4 |
+
*.pyd
|
5 |
+
.Python
|
6 |
+
env/
|
7 |
+
venv/
|
8 |
+
pip-log.txt
|
9 |
+
pip-delete-this-directory.txt
|
10 |
+
.tox/
|
11 |
+
.coverage
|
12 |
+
.coverage.*
|
13 |
+
.cache
|
14 |
+
nosetests.xml
|
15 |
+
coverage.xml
|
16 |
+
*.cover
|
17 |
+
*.log
|
18 |
+
.git
|
19 |
+
.gitignore
|
20 |
+
.mypy_cache
|
21 |
+
.pytest_cache
|
22 |
+
.hypothesis
|
23 |
+
.idea
|
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
venv
|
2 |
+
.DS_Store
|
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY ./requirements.txt /code/requirements.txt
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
8 |
+
|
9 |
+
COPY . .
|
10 |
+
|
11 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
__pycache__/main.cpython-312.pyc
ADDED
Binary file (3.78 kB). View file
|
|
app/main.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
from bs4 import BeautifulSoup
|
3 |
+
from fastapi import FastAPI
|
4 |
+
from pydantic import BaseModel
|
5 |
+
import re
|
6 |
+
|
7 |
+
|
8 |
+
app = FastAPI()
|
9 |
+
|
10 |
+
|
11 |
+
print("hello world")
|
12 |
+
|
13 |
+
@app.get("/")
|
14 |
+
async def root():
|
15 |
+
return {"status": "OK"}
|
16 |
+
|
17 |
+
class Item(BaseModel):
|
18 |
+
url: str
|
19 |
+
percentage: int
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
def extract_article_content(url):
|
24 |
+
try:
|
25 |
+
# Fetch the HTML content of the article URL
|
26 |
+
response = requests.get(url)
|
27 |
+
|
28 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
29 |
+
results = soup.find_all(['h1', 'p'])
|
30 |
+
text = [result.text for result in results]
|
31 |
+
ARTICLE = ' '.join(text)
|
32 |
+
|
33 |
+
return ARTICLE
|
34 |
+
except Exception as e:
|
35 |
+
return f"Error: {e}"
|
36 |
+
|
37 |
+
|
38 |
+
@app.post("/summarize-v1")
|
39 |
+
async def root(item: Item):
|
40 |
+
|
41 |
+
try:
|
42 |
+
|
43 |
+
article = extract_article_content(item.url)
|
44 |
+
|
45 |
+
url = "https://text-analysis12.p.rapidapi.com/summarize-text/api/v1.1"
|
46 |
+
|
47 |
+
payload = {
|
48 |
+
"language": "english",
|
49 |
+
"summary_percent": item.percentage,
|
50 |
+
'text': article
|
51 |
+
}
|
52 |
+
headers = {
|
53 |
+
"content-type": "application/json",
|
54 |
+
"X-RapidAPI-Key": "7bbb7cd865mshd68e00cace314fep11d10ejsnd6d281102968",
|
55 |
+
"X-RapidAPI-Host": "text-analysis12.p.rapidapi.com"
|
56 |
+
}
|
57 |
+
|
58 |
+
response = requests.post(url, json=payload, headers=headers).json()
|
59 |
+
|
60 |
+
|
61 |
+
#text processing
|
62 |
+
text = response["summary"].replace('\"', " ");
|
63 |
+
text = re.sub(r'\s+', ' ', text)
|
64 |
+
|
65 |
+
|
66 |
+
#return {clean_response}
|
67 |
+
return {
|
68 |
+
"summary":text}
|
69 |
+
|
70 |
+
except requests.RequestException as e:
|
71 |
+
return {"error": str(e), "status_code": 500}
|
72 |
+
|
73 |
+
@app.post("/summarize-v2")
|
74 |
+
async def root(item: Item):
|
75 |
+
|
76 |
+
try:
|
77 |
+
|
78 |
+
article = extract_article_content(item.url)
|
79 |
+
|
80 |
+
response = requests.post('https://fumes-api.onrender.com/llama3',
|
81 |
+
json={'prompt': "{ 'User': 'Summarize the following news article: '" + article + "}",
|
82 |
+
"temperature":0.6,
|
83 |
+
"topP":0.9,
|
84 |
+
"maxTokens": 200}, stream=True)
|
85 |
+
|
86 |
+
response_content = response.content.decode('utf-8')
|
87 |
+
|
88 |
+
#return {clean_response}
|
89 |
+
return {
|
90 |
+
"summary":response_content}
|
91 |
+
|
92 |
+
except requests.RequestException as e:
|
93 |
+
return {"error": str(e), "status_code": 500}
|
94 |
+
|
95 |
+
|
96 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
beautifulsoup4
|
2 |
+
requests
|
3 |
+
pydantic
|
4 |
+
uvicorn
|
5 |
+
fastapi
|