Spaces:
Sleeping
Sleeping
File size: 1,598 Bytes
cfc7f91 b0b55ac a8f34eb d425ac5 a8f34eb feafc9d a8f34eb 3cf1b30 cfc7f91 b0b55ac e85cb46 b0b55ac 982c89f e85cb46 feafc9d e85cb46 0429320 f392862 0429320 b0b55ac 0429320 1b4c032 e85cb46 b5e31dc 982c89f e85cb46 |
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 42 43 44 45 46 47 48 49 50 51 |
import gradio as gr
import torch
from transformers import AutoModel, AutoTokenizer
# Load the model
model = AutoModel.from_pretrained("openbmb/MiniCPM-V-2", trust_remote_code=True)
# Load the tokenizer
tokenizer = AutoTokenizer.from_pretrained("openbmb/MiniCPM-V-2", trust_remote_code=True)
model.eval()
# Image and text inputs for the interface
image = gr.Image(type="pil", label="Image")
question = gr.Textbox(label="Question")
# Output for the interface
answer = gr.Textbox(label="Predicted answer", show_label=True, show_copy_button=True)
title = "Sudoku Solver by FG"
description = "Sudoku Solver using MiniCPM-V-2 model by FG. Upload an image of a sudoku puzzle and ask a question to solve it."
# Define the function for solving Sudoku
def solve_sudoku(image, question):
msgs = [{"role": "user", "content": question}]
res = model.chat(
image=image,
msgs=msgs,
context=None,
tokenizer=tokenizer,
sampling=True,
temperature=0.7,
stream=True,
system_prompt="You are an AI assistant specialized in visual content analysis. Given an image and a related question, analyze the image thoroughly and provide a precise and informative answer based on the visible content. Ensure your response is clear, accurate, and directly addresses the question.",
)
return "".join(res)
# Create the Gradio interface
demo = gr.Interface(
fn=solve_sudoku,
inputs=[image, question],
outputs=answer,
title=title,
description=description,
theme="compact",
)
# Launch the interface
demo.launch(share=True)
|