Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
|
| 4 |
+
# Load TinyBERT
|
| 5 |
+
model_name = "huawei-noah/TinyBERT_General_6L_768D"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
# Streamlit App Title
|
| 10 |
+
st.title("TinyBERT Text Summarization")
|
| 11 |
+
|
| 12 |
+
# Input text box
|
| 13 |
+
input_text = st.text_area("Enter text for summarization:", height=200)
|
| 14 |
+
|
| 15 |
+
# Button to perform summarization
|
| 16 |
+
if st.button("Summarize"):
|
| 17 |
+
if input_text:
|
| 18 |
+
# Tokenize input text
|
| 19 |
+
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
|
| 20 |
+
|
| 21 |
+
# Get model outputs
|
| 22 |
+
outputs = model(**inputs)
|
| 23 |
+
|
| 24 |
+
# Display output (this is placeholder logic, adjust to your specific task)
|
| 25 |
+
st.write(f"Model output: {outputs}")
|
| 26 |
+
else:
|
| 27 |
+
st.warning("Please enter some text to summarize.")
|