Spaces:
Sleeping
Sleeping
Update app.py with improved Gradio interface and change model's torch_dtype to float32
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from PIL import Image
|
4 |
from transformers import AutoModel, AutoTokenizer
|
5 |
|
6 |
device = "cpu"
|
@@ -24,16 +23,11 @@ description = "Sudoku Solver using MiniCPM-Llama3-V-2_5"
|
|
24 |
|
25 |
# Define the function for solving Sudoku
|
26 |
def solve_sudoku(image, question):
|
27 |
-
# Convert image to RGB format if not already in RGB
|
28 |
-
image = image.convert("RGB") if image.mode != 'RGB' else image
|
29 |
msgs = [{"role": "user", "content": question}]
|
30 |
res = model.chat(
|
31 |
image=image,
|
32 |
msgs=msgs,
|
33 |
tokenizer=tokenizer,
|
34 |
-
sampling=False,
|
35 |
-
temperature=0.7,
|
36 |
-
stream=False, # Enable streaming
|
37 |
system_prompt="You are an expert in solving sudoku puzzles. Please solve the sudoku puzzle in the image correctly.",
|
38 |
)
|
39 |
return "".join(res)
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
|
|
3 |
from transformers import AutoModel, AutoTokenizer
|
4 |
|
5 |
device = "cpu"
|
|
|
23 |
|
24 |
# Define the function for solving Sudoku
|
25 |
def solve_sudoku(image, question):
|
|
|
|
|
26 |
msgs = [{"role": "user", "content": question}]
|
27 |
res = model.chat(
|
28 |
image=image,
|
29 |
msgs=msgs,
|
30 |
tokenizer=tokenizer,
|
|
|
|
|
|
|
31 |
system_prompt="You are an expert in solving sudoku puzzles. Please solve the sudoku puzzle in the image correctly.",
|
32 |
)
|
33 |
return "".join(res)
|