hadheedo commited on
Commit
50feb19
ยท
verified ยท
1 Parent(s): 1b3a96f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -86
app.py CHANGED
@@ -2,12 +2,10 @@ import streamlit as st
2
  from transformers import T5Tokenizer, T5ForConditionalGeneration
3
  import torch
4
 
5
- # Load model and tokenizer
6
- model_path = "./saved_model"
7
- tokenizer_path = "./saved_tokenizer"
8
-
9
- tokenizer = T5Tokenizer.from_pretrained(tokenizer_path)
10
- model = T5ForConditionalGeneration.from_pretrained(model_path)
11
 
12
  # Function to generate summary
13
  def generate_summary(text):
@@ -16,94 +14,21 @@ def generate_summary(text):
16
  outputs = model.generate(inputs.input_ids.to(model.device), max_length=150, length_penalty=2.0, num_beams=4, early_stopping=True)
17
  return tokenizer.decode(outputs[0], skip_special_tokens=True)
18
 
19
- # Custom CSS styling for a clean, modern interface
20
- st.markdown("""
21
- <style>
22
- .main {
23
- background-color: #f0f2f6;
24
- background-image: linear-gradient(135deg, #e6f7ff 0%, #b3e0ff 100%);
25
- font-family: 'Arial', sans-serif;
26
- }
27
- .stTextArea textarea {
28
- border: 2px solid #0078d4;
29
- border-radius: 12px;
30
- padding: 15px;
31
- font-family: 'Segoe UI', sans-serif;
32
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
33
- width: 100%;
34
- max-width: 800px;
35
- margin: 20px auto;
36
- font-size: 16px;
37
- }
38
- .stTextArea textarea:focus {
39
- border-color: #0058a3;
40
- box-shadow: 0 0 10px #4f8bf9;
41
- }
42
- .stButton>button {
43
- background-color: #29b6f6;
44
- color: white;
45
- border-radius: 25px;
46
- border: none;
47
- padding: 12px 30px;
48
- font-size: 18px;
49
- font-weight: bold;
50
- box-shadow: 0 4px 12px rgba(41, 182, 246, 0.3);
51
- transition: all 0.3s ease;
52
- }
53
- .stButton>button:hover {
54
- background-color: #0288d1;
55
- box-shadow: 0 6px 14px rgba(2, 136, 209, 0.4);
56
- transform: translateY(-2px);
57
- }
58
- .stTitle {
59
- color: #0078d4;
60
- font-size: 2.5em;
61
- text-align: center;
62
- margin-bottom: 20px;
63
- font-family: 'Segoe UI', sans-serif;
64
- }
65
- .summary-container {
66
- background-color: #ffffff;
67
- border-radius: 12px;
68
- padding: 20px;
69
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
70
- margin-top: 20px;
71
- max-width: 800px;
72
- margin: 20px auto;
73
- }
74
- .summary-title {
75
- color: #0288d1;
76
- font-weight: bold;
77
- font-size: 1.5em;
78
- margin-bottom: 10px;
79
- }
80
- .footer {
81
- text-align: center;
82
- margin-top: 50px;
83
- padding: 20px;
84
- color: #0078d4;
85
- font-style: italic;
86
- }
87
- </style>
88
- """, unsafe_allow_html=True)
89
 
90
- # Application UI
91
  st.title("๐Ÿ“ Text Summarizer App")
92
-
93
  text = st.text_area("Enter the text you want to summarize...", height=200)
94
 
95
  if st.button("Generate Summary"):
96
  if text:
97
  with st.spinner("Generating summary..."):
98
  summary = generate_summary(text)
99
- st.markdown('<div class="summary-container"><div class="summary-title">๐Ÿ“‹ Summary</div>' +
100
- summary + '</div>', unsafe_allow_html=True)
101
  else:
102
  st.warning("โš ๏ธ Please enter text to summarize.")
103
 
104
- # Footer
105
- st.markdown("""
106
- <div class="footer">
107
- Created with hadheedo
108
- </div>
109
- """, unsafe_allow_html=True)
 
2
  from transformers import T5Tokenizer, T5ForConditionalGeneration
3
  import torch
4
 
5
+ # Load model and tokenizer from Hugging Face Hub
6
+ model_name = "t5-small" # or your model name
7
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
8
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
 
 
9
 
10
  # Function to generate summary
11
  def generate_summary(text):
 
14
  outputs = model.generate(inputs.input_ids.to(model.device), max_length=150, length_penalty=2.0, num_beams=4, early_stopping=True)
15
  return tokenizer.decode(outputs[0], skip_special_tokens=True)
16
 
17
+ # Custom CSS styling (same as before)
18
+ st.markdown("""<style> ... </style>""", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ # Application UI (same as before)
21
  st.title("๐Ÿ“ Text Summarizer App")
 
22
  text = st.text_area("Enter the text you want to summarize...", height=200)
23
 
24
  if st.button("Generate Summary"):
25
  if text:
26
  with st.spinner("Generating summary..."):
27
  summary = generate_summary(text)
28
+ st.markdown('<div class="summary-container"><div class="summary-title">๐Ÿ“‹ Summary</div>' +
29
+ summary + '</div>', unsafe_allow_html=True)
30
  else:
31
  st.warning("โš ๏ธ Please enter text to summarize.")
32
 
33
+ # Footer (same as before)
34
+ st.markdown("""<div class="footer"> Created with hadheedo</div>""", unsafe_allow_html=True)