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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -5
app.py CHANGED
@@ -1,11 +1,19 @@
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")
@@ -14,9 +22,18 @@ def query(image):
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"),
@@ -25,5 +42,7 @@ iface = gr.Interface(
25
  description="Генерация описания изображения через DeepSeek VL2"
26
  )
27
 
 
28
  if __name__ == "__main__":
29
  iface.launch()
 
 
1
+ import os
2
  import requests
3
+ import gradio as gr
4
 
5
+ # API URL твоей модели
6
  API_URL = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-VL2-Small"
 
7
 
8
+ # Получаем токен из переменной окружения
9
+ API_TOKEN = os.getenv("My_token")
10
+
11
+ # Заголовки запроса
12
+ headers = {
13
+ "Authorization": f"Bearer {API_TOKEN}"
14
+ }
15
 
16
+ # Функция для отправки изображения на сервер модели
17
  def query(image):
18
  buffered = image.convert("RGB")
19
  buffered.save("temp.jpg", format="JPEG")
 
22
  data = f.read()
23
 
24
  response = requests.post(API_URL, headers=headers, data=data)
 
 
25
 
26
+ # Обработка ответа
27
+ if response.status_code == 200:
28
+ output = response.json()
29
+ if isinstance(output, list) and "generated_text" in output[0]:
30
+ return output[0]["generated_text"]
31
+ else:
32
+ return "Ошибка: Неверный формат ответа от модели."
33
+ else:
34
+ return f"Ошибка запроса: {response.status_code} - {response.text}"
35
+
36
+ # Интерфейс Gradio
37
  iface = gr.Interface(
38
  fn=query,
39
  inputs=gr.Image(type="pil"),
 
42
  description="Генерация описания изображения через DeepSeek VL2"
43
  )
44
 
45
+ # Запуск приложения
46
  if __name__ == "__main__":
47
  iface.launch()
48
+