Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,61 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
|
4 |
+
|
5 |
+
import requests
|
6 |
+
from bs4 import BeautifulSoup
|
7 |
+
import re
|
8 |
+
|
9 |
+
|
10 |
+
from transformers import pipeline
|
11 |
+
pipe = pipeline("text-generation", model="meta-llama/Llama-3.2-1B")
|
12 |
+
|
13 |
+
def get_clean_text(url):
|
14 |
+
try:
|
15 |
+
# Send a GET request to the URL
|
16 |
+
response = requests.get(url)
|
17 |
+
|
18 |
+
# Check if the request was successful
|
19 |
+
if response.status_code != 200:
|
20 |
+
return None
|
21 |
+
|
22 |
+
# Parse the HTML content using BeautifulSoup
|
23 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
24 |
+
|
25 |
+
# Remove all script and style elements
|
26 |
+
for script in soup(["script", "style"]):
|
27 |
+
script.decompose()
|
28 |
+
|
29 |
+
# Get the text from the HTML content
|
30 |
+
text = soup.get_text()
|
31 |
+
|
32 |
+
# Break the text into lines and remove leading and trailing whitespace
|
33 |
+
lines = (line.strip() for line in text.splitlines())
|
34 |
+
|
35 |
+
# Break multi-headlines into a line each
|
36 |
+
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
|
37 |
+
|
38 |
+
# Remove blank lines
|
39 |
+
text = '\n'.join(chunk for chunk in chunks if chunk)
|
40 |
+
|
41 |
+
# Remove extra whitespace
|
42 |
+
text = re.sub(r'\s+', ' ', text)
|
43 |
+
|
44 |
+
return text
|
45 |
+
|
46 |
+
except Exception as e:
|
47 |
+
print(f"An error occurred: {e}")
|
48 |
+
return None
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
def summarize(alink):
|
53 |
+
summary = ""
|
54 |
+
alink = "https://www.aljazeeramubasher.net/palestine/"
|
55 |
+
text = get_clean_text
|
56 |
+
summary = pipe(f"summarize the following news into bullet points {text}")
|
57 |
+
return summary
|
58 |
+
|
59 |
+
gr.interface(fn=summarize, input="text", output="text")
|
60 |
+
|
61 |
+
# gr.load("models/meta-llama/Llama-3.2-1B").launch()
|