Asya2025 commited on
Commit
2fe7de4
·
verified ·
1 Parent(s): be6ef46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -1,18 +1,28 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- pipe = pipeline("image-to-text", model="deepseek-ai/DeepSeek-VL2-Small")
 
5
 
6
- def predict(image):
7
- result = pipe(image)
8
- return result[0]['generated_text'] if isinstance(result, list) else result
 
 
 
 
 
 
 
 
 
9
 
10
  iface = gr.Interface(
11
- fn=predict,
12
  inputs=gr.Image(type="pil"),
13
  outputs="text",
14
- title="DeepSeek Image-to-Text Generator",
15
- description="Описание изображений через DeepSeek-VL2-Small"
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__":