AlexCool2024 commited on
Commit
40f65d2
·
verified ·
1 Parent(s): f11a794

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -2,16 +2,11 @@ import streamlit as st
2
  import numpy as np
3
  import cv2
4
  import tempfile
5
- from gradio_client import Client
6
  from PIL import Image
7
 
8
- # Проверка доступности API
9
- api_url = "https://pragnakalp-ocr-image-to-text.hf.space/--replicas/lhzf3/"
10
- try:
11
- client = Client(api_url)
12
- except Exception as e:
13
- st.error(f"Failed to initialize client: {str(e)}")
14
- st.stop()
15
 
16
  # Заголовок приложения
17
  st.title("Video Frame to Image Description")
@@ -38,13 +33,20 @@ if uploaded_file is not None:
38
  pil_image = Image.fromarray(frame_rgb)
39
  st.image(pil_image, caption=f"Random Frame {random_frame}")
40
 
 
41
  buf = tempfile.NamedTemporaryFile(suffix='.jpg', delete=False)
42
  pil_image.save(buf, format='JPEG')
43
  buf.close()
44
 
45
  try:
46
- result = client.predict("PaddleOCR", buf.name, api_name="/predict")
47
- description = result['data']
 
 
 
 
 
 
48
  st.success(f"Generated Description: {description}")
49
  except Exception as e:
50
  st.error(f"Error: Could not get a response from the model. {str(e)}")
 
2
  import numpy as np
3
  import cv2
4
  import tempfile
5
+ from gradio_client import Client, handle_file
6
  from PIL import Image
7
 
8
+ # Проверка доступности нового API
9
+ client = Client("yeecin/img2text")
 
 
 
 
 
10
 
11
  # Заголовок приложения
12
  st.title("Video Frame to Image Description")
 
33
  pil_image = Image.fromarray(frame_rgb)
34
  st.image(pil_image, caption=f"Random Frame {random_frame}")
35
 
36
+ # Сохранение кадра во временный файл для API
37
  buf = tempfile.NamedTemporaryFile(suffix='.jpg', delete=False)
38
  pil_image.save(buf, format='JPEG')
39
  buf.close()
40
 
41
  try:
42
+ # Вызов нового API для получения описания
43
+ result = client.predict(
44
+ raw_image=handle_file(buf.name),
45
+ model_n="Image Captioning",
46
+ strategy="Nucleus sampling",
47
+ api_name="/predict"
48
+ )
49
+ description = result
50
  st.success(f"Generated Description: {description}")
51
  except Exception as e:
52
  st.error(f"Error: Could not get a response from the model. {str(e)}")