Omkar1872 commited on
Commit
f74fcb6
Β·
verified Β·
1 Parent(s): 1df3e6c

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +36 -0
  2. helper.py +22 -0
  3. requirements.txt.txt +6 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from helper import extract_text_from_pdf, extract_text_from_image, generate_todo
4
+
5
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
6
+
7
+ def process_input(file):
8
+ file_type = file.name.split('.')[-1]
9
+
10
+ if file_type.lower() == "pdf":
11
+ text = extract_text_from_pdf(file.name)
12
+ elif file_type.lower() in ["png", "jpg", "jpeg"]:
13
+ text = extract_text_from_image(file.name)
14
+ else:
15
+ text = file.read().decode("utf-8")
16
+
17
+ if not text.strip():
18
+ return "No content found", ""
19
+
20
+ summary = summarizer(text, max_length=120, min_length=30, do_sample=False)[0]['summary_text']
21
+ todos = generate_todo(summary)
22
+
23
+ return summary, todos
24
+
25
+ iface = gr.Interface(
26
+ fn=process_input,
27
+ inputs=gr.File(type="file", label="Upload text/pdf/image"),
28
+ outputs=[
29
+ gr.Textbox(label="Summary", lines=5),
30
+ gr.Textbox(label="To-Do List", lines=5)
31
+ ],
32
+ title="🧠 Multimodal Productivity Agent",
33
+ description="Upload text, PDFs, or images to generate a summary and actionable to-do list."
34
+ )
35
+
36
+ iface.launch()
helper.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pdfplumber
2
+ import pytesseract
3
+ from PIL import Image
4
+
5
+ # Extract text from PDF
6
+ def extract_text_from_pdf(pdf_file):
7
+ all_text = ""
8
+ with pdfplumber.open(pdf_file) as pdf:
9
+ for page in pdf.pages:
10
+ all_text += page.extract_text() + "\n"
11
+ return all_text.strip()
12
+
13
+ # Extract text from image
14
+ def extract_text_from_image(image_file):
15
+ image = Image.open(image_file)
16
+ return pytesseract.image_to_string(image)
17
+
18
+ # Basic to-do list generator
19
+ def generate_todo(summary):
20
+ lines = summary.strip().split('.')
21
+ todos = [f"πŸ”Ή {line.strip()}" for line in lines if line.strip()]
22
+ return '\n'.join(todos)
requirements.txt.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ pdfplumber
4
+ pytesseract
5
+ Pillow
6
+ torch