File size: 1,154 Bytes
17df60f fcd23a2 17df60f 394208e 17df60f 394208e fcd23a2 842fa3a 17df60f c3aab96 394208e 3f7503f 394208e 17df60f 466ab78 17df60f 394208e 17df60f c3aab96 3f7503f | 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 | import gradio as gr
import moondream as md
from PIL import Image
import torch
# Inisialisasi model secara lokal
model = md.vl(model="vikhyatk/moondream2")
def answer_question(image, question):
if image is None:
return "No image provided"
image = image.convert("RGB")
try:
# Gunakan method .query() untuk versi library native
result = model.query(image, question)
if isinstance(result, dict) and 'answer' in result:
return result['answer']
return str(result)
except Exception as e:
return f"Error: {str(e)}"
# Interface Gradio
interface = gr.Interface(
fn=answer_question,
inputs=[
gr.Image(type="pil", label="Upload Captcha"),
gr.Textbox(label="Question", value="What is the text or number in this image?")
],
outputs=gr.Text(label="Result"),
title="Moondream Solver (Local Stable)",
description="Menggunakan library moondream native untuk stabilitas tinggi."
)
if __name__ == "__main__":
# Menambahkan konfigurasi launch untuk stabilitas di Hugging Face
interface.queue().launch(show_error=True)
|