Asya2025's picture
Update app.py
2fe7de4 verified
raw
history blame
906 Bytes
import gradio as gr
import requests
API_URL = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-VL2-Small"
API_TOKEN = "hf_..." # Твой Hugging Face токен доступа сюда (можно сгенерить)
headers = {"Authorization": f"Bearer {API_TOKEN}"}
def query(image):
buffered = image.convert("RGB")
buffered.save("temp.jpg", format="JPEG")
with open("temp.jpg", "rb") as f:
data = f.read()
response = requests.post(API_URL, headers=headers, data=data)
output = response.json()
return output[0]["generated_text"] if isinstance(output, list) else output
iface = gr.Interface(
fn=query,
inputs=gr.Image(type="pil"),
outputs="text",
title="DeepSeek Image Captioning",
description="Генерация описания изображения через DeepSeek VL2"
)
if __name__ == "__main__":
iface.launch()