tstone87 commited on
Commit
9d79b23
·
verified ·
1 Parent(s): 85b39e8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModel
3
+ from PIL import Image
4
+ import torch
5
+ import pdfplumber
6
+
7
+ # Load the model
8
+ model = AutoModel.from_pretrained("deepseek-ai/Janus-1.3B")
9
+
10
+ def process_input(input_data):
11
+ if isinstance(input_data, str):
12
+ return handle_text(input_data)
13
+ elif isinstance(input_data, Image.Image):
14
+ return handle_image(input_data)
15
+ elif isinstance(input_data, bytes):
16
+ return handle_pdf(input_data)
17
+ else:
18
+ return "Unsupported input type."
19
+
20
+ def handle_text(text):
21
+ return f"Processed text: {text}"
22
+
23
+ def handle_image(image):
24
+ return "Image processing not implemented yet."
25
+
26
+ def handle_pdf(pdf_bytes):
27
+ with pdfplumber.open(pdf_bytes) as pdf:
28
+ text = "\n".join([page.extract_text() for page in pdf.pages if page.extract_text()])
29
+ return handle_text(text)
30
+
31
+ # Create Gradio app
32
+ iface = gr.Interface(
33
+ fn=process_input,
34
+ inputs=[gr.Textbox(label="Enter text"), gr.Image(label="Upload image"), gr.File(label="Upload PDF")],
35
+ outputs=gr.Textbox(),
36
+ title="Multimodal Chatbot",
37
+ description="Handles text, images, and PDFs with the same entry point."
38
+ )
39
+
40
+ iface.launch()