File size: 1,163 Bytes
9d79b23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr
from transformers import AutoModel
from PIL import Image
import torch
import pdfplumber

# Load the model
model = AutoModel.from_pretrained("deepseek-ai/Janus-1.3B")

def process_input(input_data):
    if isinstance(input_data, str):
        return handle_text(input_data)
    elif isinstance(input_data, Image.Image):
        return handle_image(input_data)
    elif isinstance(input_data, bytes):
        return handle_pdf(input_data)
    else:
        return "Unsupported input type."

def handle_text(text):
    return f"Processed text: {text}"

def handle_image(image):
    return "Image processing not implemented yet."

def handle_pdf(pdf_bytes):
    with pdfplumber.open(pdf_bytes) as pdf:
        text = "\n".join([page.extract_text() for page in pdf.pages if page.extract_text()])
    return handle_text(text)

# Create Gradio app
iface = gr.Interface(
    fn=process_input,
    inputs=[gr.Textbox(label="Enter text"), gr.Image(label="Upload image"), gr.File(label="Upload PDF")],
    outputs=gr.Textbox(),
    title="Multimodal Chatbot",
    description="Handles text, images, and PDFs with the same entry point."
)

iface.launch()