Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,42 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import json
|
| 3 |
-
import torch
|
| 4 |
-
from transformers import pipeline
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
st.
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
st.
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
import evaluate
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Load evaluation metric
|
| 9 |
+
rouge = evaluate.load("rouge")
|
| 10 |
+
|
| 11 |
+
# Load the summarization model
|
| 12 |
+
summarizer = pipeline("summarization", model="facebook/bart-base")
|
| 13 |
+
|
| 14 |
+
st.title("📝 Text Summarization with Hugging Face & Streamlit")
|
| 15 |
+
|
| 16 |
+
# User input
|
| 17 |
+
user_input = st.text_area("Enter your text here:", "")
|
| 18 |
+
|
| 19 |
+
if st.button("Summarize"):
|
| 20 |
+
if user_input:
|
| 21 |
+
# Generate summary
|
| 22 |
+
summary = summarizer(user_input, max_length=50, min_length=5, do_sample=False)[0]["summary_text"]
|
| 23 |
+
st.subheader("Generated Summary:")
|
| 24 |
+
st.write(summary)
|
| 25 |
+
|
| 26 |
+
# Evaluate with a dummy reference summary
|
| 27 |
+
reference_summary = "Example reference summary for evaluation"
|
| 28 |
+
score = rouge.compute(predictions=[summary], references=[reference_summary])
|
| 29 |
+
|
| 30 |
+
st.subheader("ROUGE Scores:")
|
| 31 |
+
st.json(score)
|
| 32 |
+
else:
|
| 33 |
+
st.warning("⚠️ Please enter text to summarize!")
|
| 34 |
+
|
| 35 |
+
# Display latest evaluation results
|
| 36 |
+
st.subheader("Latest Evaluation Results:")
|
| 37 |
+
try:
|
| 38 |
+
with open("evaluation_results.json", "r") as f:
|
| 39 |
+
results = json.load(f)
|
| 40 |
+
st.json(results)
|
| 41 |
+
except FileNotFoundError:
|
| 42 |
+
st.write("No evaluation results found.")
|