Spaces:
Running
Running
Update app.py with improved Gradio interface and system prompt for AI assistant
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import AutoModel, AutoTokenizer
|
3 |
|
4 |
# Load the model
|
@@ -9,10 +10,13 @@ tokenizer = AutoTokenizer.from_pretrained("openbmb/MiniCPM-V-2", trust_remote_co
|
|
9 |
|
10 |
model.eval()
|
11 |
|
12 |
-
|
|
|
13 |
image = gr.Image(type="pil", label="Image")
|
14 |
-
question = gr.Textbox(
|
15 |
-
|
|
|
|
|
16 |
|
17 |
title = "Sudoku Solver by FG"
|
18 |
description = "Sudoku Solver using MiniCPM-V-2 model by FG. Upload an image of a sudoku puzzle and ask a question to solve it."
|
@@ -24,7 +28,10 @@ def solve_sudoku(image, question):
|
|
24 |
image=image,
|
25 |
msgs=msgs,
|
26 |
tokenizer=tokenizer,
|
27 |
-
|
|
|
|
|
|
|
28 |
)
|
29 |
return "".join(res)
|
30 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
from transformers import AutoModel, AutoTokenizer
|
4 |
|
5 |
# Load the model
|
|
|
10 |
|
11 |
model.eval()
|
12 |
|
13 |
+
|
14 |
+
# Image and text inputs for the interface
|
15 |
image = gr.Image(type="pil", label="Image")
|
16 |
+
question = gr.Textbox(label="Question")
|
17 |
+
|
18 |
+
# Output for the interface
|
19 |
+
answer = gr.Textbox(label="Predicted answer", show_label=True, show_copy_button=True)
|
20 |
|
21 |
title = "Sudoku Solver by FG"
|
22 |
description = "Sudoku Solver using MiniCPM-V-2 model by FG. Upload an image of a sudoku puzzle and ask a question to solve it."
|
|
|
28 |
image=image,
|
29 |
msgs=msgs,
|
30 |
tokenizer=tokenizer,
|
31 |
+
sampling=True,
|
32 |
+
temperature=0.7,
|
33 |
+
stream=True,
|
34 |
+
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.",
|
35 |
)
|
36 |
return "".join(res)
|
37 |
|