Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +33 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
load_dotenv()
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
API_URL = "https://api-inference.huggingface.co/models/microsoft/conditional-image-captioning"
|
| 8 |
+
import os
|
| 9 |
+
HEADERS = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def predict_caption(image):
|
| 13 |
+
try:
|
| 14 |
+
response = requests.post(
|
| 15 |
+
API_URL,
|
| 16 |
+
headers=HEADERS,
|
| 17 |
+
json={"inputs": image}
|
| 18 |
+
)
|
| 19 |
+
result = response.json()
|
| 20 |
+
return result[0]["generated_text"] if isinstance(result, list) else str(result)
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"Hata oluştu: {str(e)}"
|
| 23 |
+
|
| 24 |
+
demo = gr.Interface(
|
| 25 |
+
fn=predict_caption,
|
| 26 |
+
inputs=gr.Image(type="filepath"),
|
| 27 |
+
outputs="text",
|
| 28 |
+
title="Resim Açıklayıcı Proxy",
|
| 29 |
+
description="Bu Gradio arayüzü Hugging Face üzerinden resim açıklaması üretir."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
demo.launch()
|
| 33 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
requests
|
| 3 |
+
python-dotenv
|
| 4 |
+
|