cantuncok's picture
Update app.py
ae30d65 verified
raw
history blame
No virus
1.11 kB
import gradio as gr
from transformers import AutoProcessor, AutoModelForCausalLM
import torch
# Hugging Face tokeninizi çevresel değişkenden alın
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 ve işlemciyi yükleyin
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):
# Girdileri işleyin
inputs = processor(images=image, text=text, return_tensors="pt")
# Modelden yanıt alın
outputs = model.generate(**inputs)
# Çıktıyı çözümleyin
response = processor.decode(outputs[0], skip_special_tokens=True)
return response
# Gradio arayüzünü tanımlayın
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()