File size: 906 Bytes
679183c
2fe7de4
679183c
2fe7de4
 
679183c
2fe7de4
 
 
 
 
 
 
 
 
 
 
 
679183c
 
2fe7de4
679183c
 
2fe7de4
 
679183c
 
 
 
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
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()