Spaces:
Building
Building
File size: 1,987 Bytes
d46df35 4f92651 d46df35 4f92651 d46df35 4f92651 d46df35 4f92651 d46df35 4f92651 d46df35 4f92651 d46df35 4f92651 d46df35 4f92651 d46df35 4f92651 d46df35 4f92651 d46df35 4f92651 d46df35 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import gradio as gr
import requests
import io
from PIL import Image
import base64
API_KEY = "YOUR_API_KEY" # API anahtarınızı buraya girin
API_URL = "YOUR_API_URL" # API URL'nizi buraya girin
def analyze_image(image_file):
"""
Görüntüyü analiz eder ve API'den yanıt alır.
Args:
image_file: Yüklenen görüntü dosyası.
Returns:
API'den alınan yanıt metni.
"""
try:
img = Image.open(image_file.name)
buffered = io.BytesIO()
img.save(buffered, format="PNG")
encoded_string = base64.b64encode(buffered.getvalue()).decode("utf-8")
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}",
}
payload = {
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "Toplam ödeme tutarı ne kadardır?"},
{
"type": "image_url",
"image_url": {"url": f"data:image/png;base64,{encoded_string}"},
},
],
}
],
"model": "Qwen/Qwen2-VL-72B-Instruct",
"max_tokens": 2048,
"temperature": 0.7,
"top_p": 0.9,
}
response = requests.post(API_URL, headers=headers, json=payload)
response.raise_for_status() # Başarısız isteklerde hata fırlat
return response.json()["choices"][0]["message"]["content"]
except requests.exceptions.RequestException as e:
return f"API isteği hatası: {e}"
except Exception as e:
return f"Hata: {e}"
iface = gr.Interface(
fn=analyze_image,
inputs=gr.inputs.Image(type="file"),
outputs="text",
title="Ödeme Tutarı Analizi",
description="Bir görüntü yükleyin ve toplam ödeme tutarını öğrenin.",
)
iface.launch() |