forget-bta / app.py
Forgets's picture
Update app.py
0529d67 verified
raw
history blame contribute delete
829 Bytes
import gradio as gr
import torch
from PIL import Image
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load model versi open-source (Gratis selamanya)
model_id = "vikhyatk/moondream2"
revision = "2024-08-26"
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True, revision=revision)
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
def predict(image, prompt):
if image is None:
return "No image uploaded"
# Proses gambar ke model
enc_image = model.encode_image(image)
answer = model.answer_question(enc_image, prompt, tokenizer)
return answer
# Interface Gradio sederhana buat bot PHP lo
interface = gr.Interface(
fn=predict,
inputs=[gr.Image(type="pil"), gr.Textbox(label="Prompt")],
outputs=gr.Text(),
)
interface.launch()