Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
iface = gr.Interface(
|
11 |
-
fn=
|
12 |
inputs=gr.Image(type="pil"),
|
13 |
outputs="text",
|
14 |
-
title="DeepSeek Image
|
15 |
-
description="
|
16 |
)
|
17 |
|
18 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
|
4 |
+
API_URL = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-VL2-Small"
|
5 |
+
API_TOKEN = "hf_..." # Твой Hugging Face токен доступа сюда (можно сгенерить)
|
6 |
|
7 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
8 |
+
|
9 |
+
def query(image):
|
10 |
+
buffered = image.convert("RGB")
|
11 |
+
buffered.save("temp.jpg", format="JPEG")
|
12 |
+
|
13 |
+
with open("temp.jpg", "rb") as f:
|
14 |
+
data = f.read()
|
15 |
+
|
16 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
17 |
+
output = response.json()
|
18 |
+
return output[0]["generated_text"] if isinstance(output, list) else output
|
19 |
|
20 |
iface = gr.Interface(
|
21 |
+
fn=query,
|
22 |
inputs=gr.Image(type="pil"),
|
23 |
outputs="text",
|
24 |
+
title="DeepSeek Image Captioning",
|
25 |
+
description="Генерация описания изображения через DeepSeek VL2"
|
26 |
)
|
27 |
|
28 |
if __name__ == "__main__":
|