gnumanth commited on
Commit
7407d7f
Β·
verified Β·
1 Parent(s): 8fc9e84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -77
app.py CHANGED
@@ -178,80 +178,4 @@ with gr.Blocks(css="""
178
  )
179
 
180
  if __name__ == "__main__":
181
- iface.launch()
182
-
183
- import gradio as gr
184
- import google.generativeai as genai
185
- from markitdown import MarkItDown
186
- from typing import Union
187
- import os
188
-
189
- def extract_content(input_source: str) -> str:
190
- """Extract text content using MarkItDown"""
191
- try:
192
- md = MarkItDown()
193
- result = md.convert(input_source)
194
- return result.text_content
195
- except Exception as e:
196
- raise ValueError(f"Error processing {input_source}: {str(e)}")
197
-
198
- def summarize_content(content: str, api_key: str) -> str:
199
- """Summarize text using Gemini Flash"""
200
- genai.configure(api_key=os.getenv('GEMINI_KEY'))
201
- model = genai.GenerativeModel('gemini-1.5-flash')
202
- response = model.generate_content(
203
- f"Create a structured summary with key points using bullet points. "
204
- f"Focus on main ideas and important details:\n\n{content}"
205
- )
206
- return response.text
207
-
208
- def process_input(api_key: str, url: str = None, file: str = None) -> str:
209
- """Handle both URL and file inputs"""
210
- try:
211
- if url:
212
- text = extract_content(url)
213
- elif file:
214
- text = extract_content(file)
215
- else:
216
- return "⚠️ Please provide either a URL or upload a file"
217
-
218
- if not text.strip():
219
- return "❌ Error: No text could be extracted from the provided input"
220
-
221
- return summarize_content(text, api_key)
222
- except Exception as e:
223
- return f"❌ Processing Error: {str(e)}"
224
-
225
- # Gradio interface
226
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
227
- gr.Markdown("""# πŸ“„ Smart Content Summarizer
228
- **Powered by Gemini Flash & Microsoft Markitdown**""")
229
-
230
- with gr.Row():
231
- with gr.Tab("🌐 URL Input"):
232
- url_input = gr.Textbox(label="Enter URL", placeholder="https://example.com/article")
233
- url_submit = gr.Button("Summarize URL", variant="primary")
234
-
235
- with gr.Tab("πŸ“ File Upload"):
236
- file_input = gr.File(label="Upload Document (PDF, DOCX, TXT)",
237
- file_types=[".pdf", ".docx", ".txt"])
238
- file_submit = gr.Button("Summarize File", variant="primary")
239
-
240
- api_key_input = gr.Textbox(label="Google API Key", type="password",
241
- placeholder="Enter your API key here")
242
- output = gr.Markdown()
243
-
244
- url_submit.click(
245
- fn=process_input,
246
- inputs=[api_key_input, url_input, None],
247
- outputs=output
248
- )
249
-
250
- file_submit.click(
251
- fn=process_input,
252
- inputs=[api_key_input, None, file_input],
253
- outputs=output
254
- )
255
-
256
- if __name__ == "__main__":
257
- demo.launch()
 
178
  )
179
 
180
  if __name__ == "__main__":
181
+ iface.launch()