Update app.py
Browse files
app.py
CHANGED
@@ -2,13 +2,12 @@ import streamlit as st
|
|
2 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
3 |
import torch
|
4 |
|
5 |
-
#
|
6 |
model_path = "./saved_model"
|
7 |
-
tokenizer_path = "./saved_tokenizer"
|
8 |
|
9 |
try:
|
10 |
-
tokenizer = T5Tokenizer.from_pretrained(tokenizer_path)
|
11 |
model = T5ForConditionalGeneration.from_pretrained(model_path)
|
|
|
12 |
device = torch.device("cpu")
|
13 |
model.to(device)
|
14 |
model_loaded = True
|
@@ -16,7 +15,7 @@ except Exception as e:
|
|
16 |
st.error(f"Error loading model: {e}")
|
17 |
model_loaded = False
|
18 |
|
19 |
-
#
|
20 |
def generate_summary(text):
|
21 |
try:
|
22 |
inputs = ["summarize: " + text]
|
@@ -27,8 +26,40 @@ def generate_summary(text):
|
|
27 |
st.error(f"Error generating summary: {e}")
|
28 |
return None
|
29 |
|
30 |
-
#
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
st.markdown("Enter the text you want to summarize, and the application will generate a concise summary.")
|
34 |
|
@@ -49,4 +80,3 @@ if st.button("Summarize"):
|
|
49 |
st.warning("Please enter text.")
|
50 |
|
51 |
st.markdown("---")
|
52 |
-
st.markdown("This application was developed using the T5 model.")
|
|
|
2 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
3 |
import torch
|
4 |
|
5 |
+
# تحميل النموذج والـ Tokenizer
|
6 |
model_path = "./saved_model"
|
|
|
7 |
|
8 |
try:
|
|
|
9 |
model = T5ForConditionalGeneration.from_pretrained(model_path)
|
10 |
+
tokenizer = T5Tokenizer.from_pretrained(model_path)
|
11 |
device = torch.device("cpu")
|
12 |
model.to(device)
|
13 |
model_loaded = True
|
|
|
15 |
st.error(f"Error loading model: {e}")
|
16 |
model_loaded = False
|
17 |
|
18 |
+
# دالة توليد الملخص
|
19 |
def generate_summary(text):
|
20 |
try:
|
21 |
inputs = ["summarize: " + text]
|
|
|
26 |
st.error(f"Error generating summary: {e}")
|
27 |
return None
|
28 |
|
29 |
+
# تخصيص الألوان
|
30 |
+
primary_color = "#FFB6C1" # وردي فاتح
|
31 |
+
secondary_color = "#E6E6FA" # بنفسجي فاتح
|
32 |
+
text_color = "#4A4A4A" # رمادي داكن
|
33 |
+
|
34 |
+
# تخصيص واجهة المستخدم
|
35 |
+
st.set_page_config(page_title="Text Summarizer", page_icon=":sparkles:", layout="wide")
|
36 |
+
|
37 |
+
st.markdown(
|
38 |
+
f"""
|
39 |
+
<style>
|
40 |
+
body {{
|
41 |
+
color: {text_color};
|
42 |
+
background-color: {secondary_color};
|
43 |
+
}}
|
44 |
+
.stApp {{
|
45 |
+
background-color: {secondary_color};
|
46 |
+
}}
|
47 |
+
.stButton button {{
|
48 |
+
background-color: {primary_color};
|
49 |
+
color: white;
|
50 |
+
}}
|
51 |
+
.stTextArea textarea {{
|
52 |
+
background-color: white;
|
53 |
+
}}
|
54 |
+
.stTextInput input {{
|
55 |
+
background-color: white;
|
56 |
+
}}
|
57 |
+
</style>
|
58 |
+
""",
|
59 |
+
unsafe_allow_html=True,
|
60 |
+
)
|
61 |
+
|
62 |
+
st.title("✨ Text Summarization Application ✨")
|
63 |
|
64 |
st.markdown("Enter the text you want to summarize, and the application will generate a concise summary.")
|
65 |
|
|
|
80 |
st.warning("Please enter text.")
|
81 |
|
82 |
st.markdown("---")
|
|