Forgets commited on
Commit
17df60f
·
verified ·
1 Parent(s): ece54c2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ from PIL import Image
4
+ import torch
5
+
6
+ # Load model dan tokenizer
7
+ model_id = "vikhyatk/moondream2"
8
+ # Menggunakan revision terbaru agar lebih stabil
9
+ model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
10
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
11
+
12
+ def answer_question(image, question):
13
+ if image is None:
14
+ return "No image provided"
15
+
16
+ # Proses gambar ke format yang dikenali model
17
+ enc_image = model.encode_image(image)
18
+ answer = model.answer_question(enc_image, question, tokenizer)
19
+ return answer
20
+
21
+ # Interface Gradio sederhana
22
+ interface = gr.Interface(
23
+ fn=answer_question,
24
+ inputs=[gr.Image(type="pil"), gr.Textbox(label="Question")],
25
+ outputs=gr.Text(label="Answer"),
26
+ title="Moondream Captcha Solver"
27
+ )
28
+
29
+ interface.launch()