Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
|
| 4 |
+
# Load the pre-trained model and tokenizer
|
| 5 |
+
model_name = "facebook/opt-1.3b"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
# Create the Streamlit app
|
| 10 |
+
st.title("Text Summarization App")
|
| 11 |
+
text_input = st.text_input("Enter text to summarize")
|
| 12 |
+
if st.button("Summarize"):
|
| 13 |
+
input_ids = tokenizer.encode(text_input, return_tensors="pt")
|
| 14 |
+
summary_ids = model.generate(input_ids, max_length=100, min_length=20, do_sample=False)
|
| 15 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 16 |
+
st.write(summary)
|