Sandaruth commited on
Commit
1ac15c0
1 Parent(s): 2cb9699

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+
5
+ from huggingface_hub import login
6
+ from dotenv import load_dotenv
7
+ import os
8
+
9
+ # Load the environment variables from the .env file
10
+ load_dotenv()
11
+
12
+ # Retrieve the token from the .env file
13
+ huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
14
+
15
+ # Log in using the retrieved token
16
+ login(token=huggingface_token)
17
+
18
+ # Available models for summarization
19
+ models = {
20
+ "T5": "Sandaruth/T5_Full_Fine_Tuned_FINDSUM",
21
+ "BERT": "bert-base-uncased", # Note: BERT isn't designed for summarization; you can change this
22
+ "LongT5": "google/long-t5-local-base",
23
+ "Pegasus": "google/pegasus-xsum"
24
+ }
25
+
26
+ # Streamlit app layout
27
+ st.title("Summarization with Multiple Models")
28
+
29
+ # Dropdown to select the model
30
+ model_choice = st.selectbox("Select a model for summarization", models.keys())
31
+
32
+ # Text area for input
33
+ input_text = st.text_area("Enter the long text you want to summarize", height=300)
34
+
35
+ # Button to generate the summary
36
+ if st.button("Generate Summary"):
37
+ # Load the selected model and summarizer pipeline
38
+ summarizer = pipeline("summarization", model=models[model_choice])
39
+
40
+ if input_text:
41
+ # Generate the summary
42
+ summary = summarizer(input_text, max_length=150, min_length=30, do_sample=False)
43
+
44
+ # Display the summary
45
+ st.subheader("Generated Summary")
46
+ st.write(summary[0]['summary_text'])
47
+ else:
48
+ st.write("Please enter text to summarize!")