yakki233 commited on
Commit
f7bd5ba
·
verified ·
1 Parent(s): 37da1c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -8,14 +8,14 @@ from PIL import Image
8
  import pypdfium2 as pdfium
9
  import gradio as gr
10
 
11
- # 从环境变量中读取 HF API Token
12
- HF_API_TOKEN = os.environ.get("HF_API_TOKEN")
13
  if HF_API_TOKEN is None:
14
  raise RuntimeError(
15
- "环境变量 HF_API_TOKEN 未设置,请在 Space 的 Settings -> Variables 中添加一个名为 HF_API_TOKEN 的 Secret。"
16
  )
17
 
18
- # 使用 OCR 模型
19
  MODEL_ID = "tencent/HunyuanOCR"
20
  API_URL = f"https://api-inference.huggingface.co/models/{MODEL_ID}"
21
  HEADERS = {"Authorization": f"Bearer {HF_API_TOKEN}"}
@@ -33,6 +33,8 @@ def image_to_base64(image: Image.Image) -> str:
33
  def call_ocr_model(image: Image.Image) -> str:
34
  """对单张图片调用 HunyuanOCR"""
35
  img_b64 = image_to_base64(image)
 
 
36
  payload = {
37
  "inputs": {
38
  "image": img_b64
 
8
  import pypdfium2 as pdfium
9
  import gradio as gr
10
 
11
+ # 从环境变量中读取你的 OCR token(变量名:ocr_model)
12
+ HF_API_TOKEN = os.environ.get("ocr_model")
13
  if HF_API_TOKEN is None:
14
  raise RuntimeError(
15
+ "环境变量 ocr_model 未设置,请在 Space 的 Settings -> Variables 中添加一个名为 ocr_model 的 Secret。"
16
  )
17
 
18
+ # 使用 OCR 模型(保持你要的模型名不变)
19
  MODEL_ID = "tencent/HunyuanOCR"
20
  API_URL = f"https://api-inference.huggingface.co/models/{MODEL_ID}"
21
  HEADERS = {"Authorization": f"Bearer {HF_API_TOKEN}"}
 
33
  def call_ocr_model(image: Image.Image) -> str:
34
  """对单张图片调用 HunyuanOCR"""
35
  img_b64 = image_to_base64(image)
36
+
37
+ # 绝大多数 image-text-to-text 模型都接受这种 payload 结构
38
  payload = {
39
  "inputs": {
40
  "image": img_b64