Spaces:
Configuration error
Configuration error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +32 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,33 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Model name
|
| 6 |
+
MODEL_NAME = "AbdullahAlnemr1/flan-t5-summarizer"
|
| 7 |
+
|
| 8 |
+
# Load tokenizer and model
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 10 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
| 11 |
+
|
| 12 |
+
st.title("FLAN‑T5 Text Summarizer")
|
| 13 |
+
|
| 14 |
+
input_text = st.text_area("Enter text to summarize:", height=200)
|
| 15 |
+
|
| 16 |
+
max_new_tokens = st.slider("Max summary length (tokens)", min_value=20, max_value=200, value=100)
|
| 17 |
+
|
| 18 |
+
if st.button("Generate Summary"):
|
| 19 |
+
if input_text.strip() == "":
|
| 20 |
+
st.warning("Please enter some text to summarize.")
|
| 21 |
+
else:
|
| 22 |
+
# Tokenize input
|
| 23 |
+
inputs = tokenizer(input_text, return_tensors="pt", truncation=True)
|
| 24 |
+
# Generate summary
|
| 25 |
+
outputs = model.generate(
|
| 26 |
+
inputs["input_ids"],
|
| 27 |
+
max_new_tokens=max_new_tokens,
|
| 28 |
+
num_beams=4,
|
| 29 |
+
early_stopping=True
|
| 30 |
+
)
|
| 31 |
+
summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 32 |
+
st.subheader("Summary:")
|
| 33 |
+
st.write(summary)
|
|
|
|
|
|
|
|
|
|
|
|