Lakshan A C Withange commited on
Commit
f4b81bf
Β·
1 Parent(s): 4d5ba13

added the project file

Browse files
.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
.idea/SummarizeAI_Pro.iml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/venv" />
6
+ </content>
7
+ <orderEntry type="inheritedJdk" />
8
+ <orderEntry type="sourceFolder" forTests="false" />
9
+ </component>
10
+ <component name="PyDocumentationSettings">
11
+ <option name="format" value="PLAIN" />
12
+ <option name="myDocStringFormat" value="Plain" />
13
+ </component>
14
+ </module>
.idea/inspectionProfiles/Project_Default.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
5
+ <option name="ignoredPackages">
6
+ <value>
7
+ <list size="1">
8
+ <item index="0" class="java.lang.String" itemvalue="accelerate" />
9
+ </list>
10
+ </value>
11
+ </option>
12
+ </inspection_tool>
13
+ </profile>
14
+ </component>
.idea/inspectionProfiles/profiles_settings.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="USE_PROJECT_PROFILE" value="false" />
4
+ <version value="1.0" />
5
+ </settings>
6
+ </component>
.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Black">
4
+ <option name="sdkName" value="Python 3.11 (SummarizeAI_Pro)" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (SummarizeAI_Pro)" project-jdk-type="Python SDK" />
7
+ </project>
.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/SummarizeAI_Pro.iml" filepath="$PROJECT_DIR$/.idea/SummarizeAI_Pro.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
app.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from peft import PeftModel
3
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
4
+ import torch
5
+
6
+
7
+ @st.cache_resource
8
+ def load_model():
9
+ """Load the PEFT model and tokenizer once and cache them"""
10
+ base_model = AutoModelForSeq2SeqLM.from_pretrained("t5-small")
11
+ peft_model = PeftModel.from_pretrained(base_model, "Lakshan2003/finetuned-xsum")
12
+ tokenizer = AutoTokenizer.from_pretrained("Lakshan2003/finetuned-xsum")
13
+ return peft_model, tokenizer
14
+
15
+
16
+ def generate_summary(text, model, tokenizer, max_length=128, min_length=30):
17
+ """Generate summary using the PEFT model"""
18
+ # Move model to GPU if available
19
+ device = "cuda" if torch.cuda.is_available() else "cpu"
20
+ model = model.to(device)
21
+
22
+ # Prepare the input text
23
+ prefix = "summarize: "
24
+ input_text = prefix + text
25
+
26
+ # Tokenize
27
+ inputs = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True)
28
+ inputs = {k: v.to(device) for k, v in inputs.items()}
29
+
30
+ # Generate summary
31
+ with torch.no_grad():
32
+ output_ids = model.generate(
33
+ input_ids=inputs["input_ids"],
34
+ attention_mask=inputs["attention_mask"],
35
+ max_length=max_length,
36
+ min_length=min_length,
37
+ num_beams=4,
38
+ length_penalty=2.0,
39
+ early_stopping=True,
40
+ no_repeat_ngram_size=3
41
+ )
42
+
43
+ # Decode the summary
44
+ summary = tokenizer.decode(output_ids[0], skip_special_tokens=True)
45
+ return summary
46
+
47
+
48
+ def main():
49
+ st.set_page_config(
50
+ page_title="SummarizeAI Pro",
51
+ page_icon="✨",
52
+ layout="wide"
53
+ )
54
+
55
+ # Custom CSS
56
+ st.markdown("""
57
+ <style>
58
+ .main-title {
59
+ text-align: center;
60
+ color: #1E88E5;
61
+ font-size: 3rem !important;
62
+ font-weight: 700;
63
+ margin-bottom: 1rem;
64
+ }
65
+ .subtitle {
66
+ text-align: center;
67
+ color: #424242;
68
+ font-size: 1.2rem !important;
69
+ margin-bottom: 2rem;
70
+ }
71
+ </style>
72
+ """, unsafe_allow_html=True)
73
+
74
+ # App title and subtitle
75
+ st.markdown("<h1 class='main-title'>✨ SummarizeAI Pro</h1>", unsafe_allow_html=True)
76
+ st.markdown("<p class='subtitle'>Transform lengthy text into concise, meaningful summaries with AI</p>",
77
+ unsafe_allow_html=True)
78
+
79
+ # Load model and tokenizer
80
+ with st.spinner("Loading model... (this may take a few moments)"):
81
+ model, tokenizer = load_model()
82
+
83
+ # Input text area
84
+ text = st.text_area(
85
+ "πŸ“ Enter your text below:",
86
+ height=200,
87
+ placeholder="Paste your text here and let SummarizeAI Pro work its magic..."
88
+ )
89
+
90
+ # Create three columns for better layout
91
+ col1, col2, col3 = st.columns([1, 1, 1])
92
+
93
+ with col1:
94
+ max_length = st.slider("Maximum summary length", 50, 250, 128)
95
+ with col2:
96
+ min_length = st.slider("Minimum summary length", 10, 100, 30)
97
+ with col3:
98
+ st.markdown("<br>", unsafe_allow_html=True) # Spacing
99
+ generate_button = st.button("✨ Generate Summary", use_container_width=True)
100
+
101
+ if generate_button:
102
+ if text:
103
+ with st.spinner("✨ AI is crafting your summary..."):
104
+ try:
105
+ summary = generate_summary(text, model, tokenizer,
106
+ max_length=max_length,
107
+ min_length=min_length)
108
+
109
+ st.markdown("### πŸ“Š Summary Results")
110
+
111
+ # Create columns for statistics
112
+ stat_col1, stat_col2 = st.columns(2)
113
+ with stat_col1:
114
+ st.info(f"πŸ“„ Original text: {len(text.split())} words")
115
+ with stat_col2:
116
+ st.info(f"βœ‚οΈ Summarized text: {len(summary.split())} words")
117
+
118
+ # Display summary in a nice box
119
+ st.markdown("### ✨ Generated Summary")
120
+ st.markdown(f"""
121
+ <div style="
122
+ padding: 20px;
123
+ border-radius: 10px;
124
+ background-color: #f0f2f6;
125
+ border-left: 5px solid #1E88E5;
126
+ ">
127
+ {summary}
128
+ </div>
129
+ """, unsafe_allow_html=True)
130
+
131
+ except Exception as e:
132
+ st.error(f"🚫 An error occurred: {str(e)}")
133
+ else:
134
+ st.warning("⚠️ Please enter some text to summarize.")
135
+
136
+ # Sidebar with enhanced styling
137
+ st.sidebar.markdown("## 🎯 About SummarizeAI Pro")
138
+ st.sidebar.markdown("""
139
+ SummarizeAI Pro uses advanced AI technology powered by a PEFT-tuned T5 model
140
+ to generate accurate and concise summaries while preserving the key points
141
+ of your text.
142
+ """)
143
+
144
+ st.sidebar.markdown("## πŸ“– How to Use")
145
+ st.sidebar.markdown("""
146
+ 1. πŸ“ Paste your text in the input box
147
+ 2. 🎚️ Adjust summary length with sliders
148
+ 3. πŸš€ Click 'Generate Summary'
149
+ 4. ✨ Get your AI-powered summary
150
+ """)
151
+
152
+ # Footer
153
+ st.markdown("""
154
+ <div style='text-align: center; color: #666; padding: 20px;'>
155
+ <p>Made with ❀️ by SummarizeAI Pro Team</p>
156
+ </div>
157
+ """, unsafe_allow_html=True)
158
+
159
+
160
+ if __name__ == "__main__":
161
+ main()