|
import gradio as gr |
|
from transformers import AutoProcessor, AutoModelForCausalLM |
|
import torch |
|
|
|
|
|
hf_token = os.getenv("HF_TOKEN") |
|
if not hf_token: |
|
raise ValueError("HF_TOKEN çevresel değişkeni ayarlanmamış. Lütfen Hugging Face token'ınızı ayarlayın.") |
|
|
|
|
|
model_name = "meta-llama/Llama-3.2-90B-Vision-Instruct" |
|
processor = AutoProcessor.from_pretrained(model_name) |
|
model = AutoModelForCausalLM.from_pretrained(model_name) |
|
|
|
def predict(image, text): |
|
|
|
inputs = processor(images=image, text=text, return_tensors="pt") |
|
|
|
outputs = model.generate(**inputs) |
|
|
|
response = processor.decode(outputs[0], skip_special_tokens=True) |
|
return response |
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict, |
|
inputs=["image", "text"], |
|
outputs="text", |
|
title="Llama 3.2 90B Vision Instruct Demo", |
|
description="Bir görüntü ve metin girdisi alarak yanıt üreten model." |
|
) |
|
|
|
interface.launch() |