Spaces:
Running
Running
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() | |