Spaces:
Configuration error
Configuration error
import os | |
import requests | |
import gradio as gr | |
# API URL твоей модели | |
API_URL = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-VL2-Small" | |
# Получаем токен из переменной окружения | |
API_TOKEN = os.getenv("My_token") | |
# Заголовки запроса | |
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) | |
# Обработка ответа | |
if response.status_code == 200: | |
output = response.json() | |
if isinstance(output, list) and "generated_text" in output[0]: | |
return output[0]["generated_text"] | |
else: | |
return "Ошибка: Неверный формат ответа от модели." | |
else: | |
return f"Ошибка запроса: {response.status_code} - {response.text}" | |
# Интерфейс Gradio | |
iface = gr.Interface( | |
fn=query, | |
inputs=gr.Image(type="pil"), | |
outputs="text", | |
title="DeepSeek Image Captioning", | |
description="Генерация описания изображения через DeepSeek VL2" | |
) | |
# Запуск приложения | |
if __name__ == "__main__": | |
iface.launch() | |