Shuja007 commited on
Commit
104fe94
·
verified ·
1 Parent(s): 5da495c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ # Load the tokenizer and model
5
+ @st.cache_resource
6
+ def load_model():
7
+ model_name = "your-huggingface-username/your-model-repo"
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
10
+ return tokenizer, model
11
+
12
+ tokenizer, model = load_model()
13
+
14
+ st.title("Summarization with BART")
15
+
16
+ # Text input
17
+ dialogue = st.text_area("Enter the dialogue to summarize:", height=200)
18
+
19
+ # Summarize button
20
+ if st.button("Summarize"):
21
+ inputs = tokenizer(dialogue, max_length=512, truncation=True, return_tensors="pt")
22
+ summary_ids = model.generate(inputs["input_ids"], max_length=128, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
23
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
24
+ st.write("### Summary")
25
+ st.write(summary)