Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,59 @@
|
|
1 |
-
import gdown
|
2 |
-
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
# https://drive.google.com/drive/folders/17G-ejd4scK1DYko5k0ssXZjEy7P-ClI6
|
5 |
|
6 |
import streamlit as st
|
7 |
-
import
|
8 |
import torch
|
9 |
from transformers import pipeline
|
10 |
|
11 |
-
# Function to download the model from Google Drive
|
12 |
def download_file_from_drive(file_id, output_path):
|
13 |
-
url = f'https://drive.google.com/uc?id={file_id}'
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Replace 'YOUR_FILE_ID' with the actual file ID of your model
|
17 |
file_id = '1A2B3C4D5E6F7G8H9I0J'
|
18 |
output_path = 'model.pt'
|
19 |
|
20 |
# Download the model file
|
21 |
-
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Load the model
|
24 |
-
|
25 |
-
model.
|
|
|
|
|
|
|
|
|
26 |
|
27 |
# Initialize the summarization pipeline
|
28 |
summarizer = pipeline('summarization', model=model)
|
@@ -37,8 +68,11 @@ text_input = st.text_area("Enter text to summarize", height=300)
|
|
37 |
if st.button("Summarize"):
|
38 |
if text_input:
|
39 |
with st.spinner("Generating summary..."):
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
43 |
else:
|
44 |
st.warning("Please enter some text to summarize.")
|
|
|
1 |
+
# import gdown
|
2 |
+
# import torch
|
3 |
+
|
4 |
+
# # https://drive.google.com/drive/folders/17G-ejd4scK1DYko5k0ssXZjEy7P-ClI6
|
5 |
+
|
6 |
+
# import streamlit as st
|
7 |
+
# import gdown
|
8 |
+
# import torch
|
9 |
+
# from transformers import pipeline
|
10 |
+
|
11 |
+
# # Function to download the model from Google Drive
|
12 |
+
# def download_file_from_drive(file_id, output_path):
|
13 |
+
# url = f'https://drive.google.com/uc?id={file_id}'
|
14 |
+
# gdown.download(url, output_path, quiet=False)
|
15 |
+
|
16 |
+
# # Replace 'YOUR_FILE_ID' with the actual file ID of your model
|
17 |
+
# file_id = '1A2B3C4D5E6F7G8H9I0J'
|
18 |
+
|
19 |
|
|
|
20 |
|
21 |
import streamlit as st
|
22 |
+
import requests
|
23 |
import torch
|
24 |
from transformers import pipeline
|
25 |
|
26 |
+
# Function to download the model from Google Drive using requests
|
27 |
def download_file_from_drive(file_id, output_path):
|
28 |
+
url = f'https://drive.google.com/uc?export=download&id={file_id}'
|
29 |
+
response = requests.get(url, stream=True)
|
30 |
+
|
31 |
+
if response.status_code == 200:
|
32 |
+
with open(output_path, 'wb') as f:
|
33 |
+
for chunk in response.iter_content(chunk_size=8192):
|
34 |
+
if chunk:
|
35 |
+
f.write(chunk)
|
36 |
+
else:
|
37 |
+
raise Exception(f"Failed to download file: Status code {response.status_code}")
|
38 |
|
39 |
# Replace 'YOUR_FILE_ID' with the actual file ID of your model
|
40 |
file_id = '1A2B3C4D5E6F7G8H9I0J'
|
41 |
output_path = 'model.pt'
|
42 |
|
43 |
# Download the model file
|
44 |
+
try:
|
45 |
+
download_file_from_drive(file_id, output_path)
|
46 |
+
except Exception as e:
|
47 |
+
st.error(f"Error downloading file: {e}")
|
48 |
+
st.stop()
|
49 |
|
50 |
# Load the model
|
51 |
+
try:
|
52 |
+
model = torch.load(output_path)
|
53 |
+
model.eval()
|
54 |
+
except Exception as e:
|
55 |
+
st.error(f"Error loading model: {e}")
|
56 |
+
st.stop()
|
57 |
|
58 |
# Initialize the summarization pipeline
|
59 |
summarizer = pipeline('summarization', model=model)
|
|
|
68 |
if st.button("Summarize"):
|
69 |
if text_input:
|
70 |
with st.spinner("Generating summary..."):
|
71 |
+
try:
|
72 |
+
summary = summarizer(text_input, max_length=150, min_length=30, do_sample=False)
|
73 |
+
st.subheader("Summary")
|
74 |
+
st.write(summary[0]['summary_text'])
|
75 |
+
except Exception as e:
|
76 |
+
st.error(f"Error during summarization: {e}")
|
77 |
else:
|
78 |
st.warning("Please enter some text to summarize.")
|