girishwangikar commited on
Commit
c04c6e5
·
verified ·
1 Parent(s): edbf89c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -17
app.py CHANGED
@@ -32,15 +32,11 @@ def chunk_text(text):
32
  def summarize_chunks(chunks, conciseness):
33
  # Adjust the prompts based on the conciseness level
34
  map_prompt_template = f"""Write a {'very concise' if conciseness > 0.7 else 'detailed'} summary of the following text, focusing on the {'most crucial' if conciseness > 0.7 else 'key'} points:
35
-
36
  "{{text}}"
37
-
38
  {'CONCISE' if conciseness > 0.7 else 'DETAILED'} SUMMARY:"""
39
 
40
  combine_prompt_template = f"""Write a {'highly condensed' if conciseness > 0.7 else 'comprehensive'} summary of the following text, capturing the {'essential' if conciseness > 0.7 else 'key'} points and main ideas:
41
-
42
  "{{text}}"
43
-
44
  {'CONDENSED' if conciseness > 0.7 else 'COMPREHENSIVE'} SUMMARY:"""
45
 
46
  map_prompt = PromptTemplate(template=map_prompt_template, input_variables=["text"])
@@ -84,20 +80,77 @@ def summarize_content(pdf_file, text_input, conciseness):
84
  final_summary = summarize_chunks(chunks, conciseness)
85
  return final_summary
86
 
 
 
 
 
 
 
 
 
 
 
87
  with gr.Blocks(theme=gr.themes.Soft()) as iface:
 
88
  gr.Markdown(
89
  """
90
- # PDF And Text Summarizer
91
- ### Advanced PDF and Text Summarization with Conciseness Control
92
- - Upload your PDF document or enter text directly, adjust the conciseness level, and let AI generate a summary.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  """
94
  )
95
 
96
  with gr.Row():
97
  with gr.Column(scale=1):
98
  input_pdf = gr.File(label="Upload PDF (optional)", file_types=[".pdf"])
99
- input_text = gr.Textbox(label="Or enter text here", lines=5, placeholder="Paste or type your text here...")
100
- conciseness_slider = gr.Slider(minimum=0, maximum=1, value=0.5, step=0.1, label="Conciseness Level")
 
 
 
 
 
 
 
 
 
 
101
  submit_btn = gr.Button("Generate Summary", variant="primary")
102
 
103
  with gr.Column(scale=2):
@@ -106,17 +159,24 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
106
  gr.Markdown(
107
  """
108
  ### How it works
109
- 1. Upload a PDF file or enter text directly
110
- 2. Adjust the conciseness level:
111
  - 0 (Most detailed) to 1 (Most concise)
112
- 3. Click "Generate Summary"
113
- 4. Wait for the AI to process and summarize your content
114
- 5. Review the generated summary
115
-
116
  *Powered by LLAMA 3.1 8B model and LangChain*
117
  """
118
  )
119
 
120
- submit_btn.click(summarize_content, inputs=[input_pdf, input_text, conciseness_slider], outputs=output)
 
 
 
 
 
 
 
 
121
 
122
- iface.launch()
 
32
  def summarize_chunks(chunks, conciseness):
33
  # Adjust the prompts based on the conciseness level
34
  map_prompt_template = f"""Write a {'very concise' if conciseness > 0.7 else 'detailed'} summary of the following text, focusing on the {'most crucial' if conciseness > 0.7 else 'key'} points:
 
35
  "{{text}}"
 
36
  {'CONCISE' if conciseness > 0.7 else 'DETAILED'} SUMMARY:"""
37
 
38
  combine_prompt_template = f"""Write a {'highly condensed' if conciseness > 0.7 else 'comprehensive'} summary of the following text, capturing the {'essential' if conciseness > 0.7 else 'key'} points and main ideas:
 
39
  "{{text}}"
 
40
  {'CONDENSED' if conciseness > 0.7 else 'COMPREHENSIVE'} SUMMARY:"""
41
 
42
  map_prompt = PromptTemplate(template=map_prompt_template, input_variables=["text"])
 
80
  final_summary = summarize_chunks(chunks, conciseness)
81
  return final_summary
82
 
83
+ FOOTER_TEXT = """
84
+ <footer>
85
+ <p>If you enjoyed the functionality of the app, please leave a like!<br>
86
+ Check out more on
87
+ <a href="https://www.linkedin.com/in/girish-wangikar/" target="_blank">LinkedIn</a> |
88
+ <a href="https://girishwangikar.github.io/Girish_Wangikar_Portfolio.github.io/" target="_blank">Portfolio</a>
89
+ </p>
90
+ </footer>
91
+ """
92
+
93
  with gr.Blocks(theme=gr.themes.Soft()) as iface:
94
+ # Add custom CSS for styling
95
  gr.Markdown(
96
  """
97
+ <style>
98
+ .title {
99
+ text-align: center;
100
+ }
101
+ .description {
102
+ text-align: center;
103
+ }
104
+ footer {
105
+ text-align: center;
106
+ padding: 10px;
107
+ width: 100%;
108
+ background-color: rgba(240, 240, 240, 0.8);
109
+ z-index: 1000;
110
+ position: relative;
111
+ margin-top: 10px;
112
+ color: black;
113
+ }
114
+ /* Optional: Adjust link styles in footer */
115
+ footer a {
116
+ color: #1a0dab;
117
+ text-decoration: none;
118
+ }
119
+ footer a:hover {
120
+ text-decoration: underline;
121
+ }
122
+ </style>
123
+ """
124
+ )
125
+
126
+ # Title and Description with center alignment
127
+ gr.Markdown(
128
+ """
129
+ <div class="title">
130
+ # PDF And Text Summarizer
131
+ </div>
132
+ <div class="description">
133
+ ### Advanced PDF and Text Summarization with Conciseness Control
134
+ - Upload your PDF document or enter text directly, adjust the conciseness level, and let AI generate a summary.
135
+ </div>
136
  """
137
  )
138
 
139
  with gr.Row():
140
  with gr.Column(scale=1):
141
  input_pdf = gr.File(label="Upload PDF (optional)", file_types=[".pdf"])
142
+ input_text = gr.Textbox(
143
+ label="Or enter text here",
144
+ lines=5,
145
+ placeholder="Paste or type your text here..."
146
+ )
147
+ conciseness_slider = gr.Slider(
148
+ minimum=0,
149
+ maximum=1,
150
+ value=0.5,
151
+ step=0.1,
152
+ label="Conciseness Level"
153
+ )
154
  submit_btn = gr.Button("Generate Summary", variant="primary")
155
 
156
  with gr.Column(scale=2):
 
159
  gr.Markdown(
160
  """
161
  ### How it works
162
+ 1. **Upload a PDF file or enter text directly**
163
+ 2. **Adjust the conciseness level:**
164
  - 0 (Most detailed) to 1 (Most concise)
165
+ 3. **Click "Generate Summary"**
166
+ 4. **Wait for the AI to process and summarize your content**
167
+ 5. **Review the generated summary**
 
168
  *Powered by LLAMA 3.1 8B model and LangChain*
169
  """
170
  )
171
 
172
+ # Add the footer at the end
173
+ gr.Markdown(FOOTER_TEXT)
174
+
175
+ # Define the action for the submit button
176
+ submit_btn.click(
177
+ summarize_content,
178
+ inputs=[input_pdf, input_text, conciseness_slider],
179
+ outputs=output
180
+ )
181
 
182
+ iface.launch()