| import gradio as gr |
| import moondream as md |
| from PIL import Image |
| import torch |
|
|
| |
| model = md.vl(model="vikhyatk/moondream2") |
|
|
| def answer_question(image, question): |
| if image is None: |
| return "No image provided" |
| |
| image = image.convert("RGB") |
| |
| try: |
| |
| 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 = 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__": |
| |
| interface.queue().launch(show_error=True) |
|
|