Update app.py
Browse files
app.py
CHANGED
|
@@ -4,22 +4,18 @@ from PIL import Image
|
|
| 4 |
import torch
|
| 5 |
|
| 6 |
# Inisialisasi model secara lokal
|
| 7 |
-
# Perhatikan: Kita memanggil md.vl() tapi pastikan model dimuat dengan benar
|
| 8 |
model = md.vl(model="vikhyatk/moondream2")
|
| 9 |
|
| 10 |
def answer_question(image, question):
|
| 11 |
if image is None:
|
| 12 |
return "No image provided"
|
| 13 |
|
| 14 |
-
# Pastikan format gambar benar
|
| 15 |
image = image.convert("RGB")
|
| 16 |
|
| 17 |
try:
|
| 18 |
-
#
|
| 19 |
-
# Kita langsung menggunakan method .query()
|
| 20 |
result = model.query(image, question)
|
| 21 |
|
| 22 |
-
# Output biasanya berupa dictionary {'answer': '...'}
|
| 23 |
if isinstance(result, dict) and 'answer' in result:
|
| 24 |
return result['answer']
|
| 25 |
return str(result)
|
|
@@ -40,4 +36,5 @@ interface = gr.Interface(
|
|
| 40 |
)
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|
| 43 |
-
|
|
|
|
|
|
| 4 |
import torch
|
| 5 |
|
| 6 |
# Inisialisasi model secara lokal
|
|
|
|
| 7 |
model = md.vl(model="vikhyatk/moondream2")
|
| 8 |
|
| 9 |
def answer_question(image, question):
|
| 10 |
if image is None:
|
| 11 |
return "No image provided"
|
| 12 |
|
|
|
|
| 13 |
image = image.convert("RGB")
|
| 14 |
|
| 15 |
try:
|
| 16 |
+
# Gunakan method .query() untuk versi library native
|
|
|
|
| 17 |
result = model.query(image, question)
|
| 18 |
|
|
|
|
| 19 |
if isinstance(result, dict) and 'answer' in result:
|
| 20 |
return result['answer']
|
| 21 |
return str(result)
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
if __name__ == "__main__":
|
| 39 |
+
# Menambahkan konfigurasi launch untuk stabilitas di Hugging Face
|
| 40 |
+
interface.queue().launch(show_error=True)
|