waqasali1707 commited on
Commit
be13547
·
verified ·
1 Parent(s): 8a7d4b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -1,21 +1,33 @@
1
  import streamlit as st
2
  import torch
3
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
 
 
4
  import os
 
5
  from zipfile import ZipFile
6
 
7
- # Streamlit UI for uploading model
8
- st.title("Text Summarizer")
 
 
9
 
10
- uploaded_file = st.file_uploader("Upload the saved model.zip file", type="zip")
 
11
 
12
- if uploaded_file is not None:
13
- # Extract the uploaded zip file
14
- with ZipFile(uploaded_file, 'r') as zip_ref:
15
- zip_ref.extractall("model_directory")
16
 
17
- # Load the model from the extracted directory
18
  try:
 
 
 
 
 
 
 
 
19
  model_path = "model_directory"
20
  tokenizer = AutoTokenizer.from_pretrained(model_path)
21
  model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
@@ -46,4 +58,4 @@ if text:
46
  st.write(output)
47
 
48
  except Exception as e:
49
- st.error(f"An error occurred during summarization: {e}")
 
1
  import streamlit as st
2
  import torch
3
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
4
+ from pydrive.auth import GoogleAuth
5
+ from pydrive.drive import GoogleDrive
6
  import os
7
+ from io import BytesIO
8
  from zipfile import ZipFile
9
 
10
+ # Initialize Google Auth and Drive
11
+ gauth = GoogleAuth()
12
+ gauth.LocalWebserverAuth() # Authenticates and opens a browser window
13
+ drive = GoogleDrive(gauth)
14
 
15
+ # Streamlit UI
16
+ st.title("Text Summarizer")
17
 
18
+ # Enter the file ID of your model.zip on Google Drive
19
+ model_file_id = st.text_input("Enter the Google Drive file ID of the model.zip")
 
 
20
 
21
+ if model_file_id:
22
  try:
23
+ # Download the file from Google Drive
24
+ downloaded = drive.CreateFile({'id': model_file_id}).GetContentString()
25
+
26
+ # Load the model from the downloaded zip file
27
+ with ZipFile(BytesIO(downloaded.encode()), 'r') as zip_ref:
28
+ zip_ref.extractall("model_directory")
29
+
30
+ # Load the model from the extracted directory
31
  model_path = "model_directory"
32
  tokenizer = AutoTokenizer.from_pretrained(model_path)
33
  model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
 
58
  st.write(output)
59
 
60
  except Exception as e:
61
+ st.error(f"An error occurred during summarization: {e}")