OppaAI commited on
Commit
406e27f
·
verified ·
1 Parent(s): dac9550

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -12,10 +12,9 @@ HF_DATASET_REPO = "OppaAI/Robot_MCP"
12
  HF_VLM_MODEL = "Qwen/Qwen2.5-VL-7B-Instruct"
13
 
14
  # --- Helper Functions ---
15
- def save_and_upload_image(image_b64):
16
  """Save image to /tmp and upload to HF dataset."""
17
  image_bytes = base64.b64decode(image_b64)
18
- # Use a unique filename to prevent conflicts in /tmp
19
  local_tmp_path = f"/tmp/tmp.jpg"
20
  with open(local_tmp_path, "wb") as f:
21
  f.write(image_bytes)
@@ -25,13 +24,14 @@ def save_and_upload_image(image_b64):
25
  path_or_fileobj=local_tmp_path,
26
  path_in_repo=path_in_repo,
27
  repo_id=HF_DATASET_REPO,
28
- token=HF_TOKEN,
29
  repo_type="dataset"
30
  )
31
 
32
  hf_image_url = f"https://huggingface.co/datasets/{HF_DATASET_REPO}/resolve/main/{path_in_repo}"
33
  return local_tmp_path, hf_image_url, path_in_repo, len(image_bytes)
34
 
 
35
  # --- Main MCP function ---
36
  def process_and_describe(payload: dict):
37
  try:
@@ -44,7 +44,7 @@ def process_and_describe(payload: dict):
44
  image_b64 = payload["image_b64"]
45
 
46
  # 2️⃣ Save image temporarily (for tracking)
47
- local_tmp_path, hf_url, path_in_repo, size_bytes = save_and_upload_image(image_b64)
48
 
49
  # 3️⃣ Initialize HF client per request
50
  hf_client = InferenceClient(token=hf_token)
 
12
  HF_VLM_MODEL = "Qwen/Qwen2.5-VL-7B-Instruct"
13
 
14
  # --- Helper Functions ---
15
+ def save_and_upload_image(image_b64, hf_token):
16
  """Save image to /tmp and upload to HF dataset."""
17
  image_bytes = base64.b64decode(image_b64)
 
18
  local_tmp_path = f"/tmp/tmp.jpg"
19
  with open(local_tmp_path, "wb") as f:
20
  f.write(image_bytes)
 
24
  path_or_fileobj=local_tmp_path,
25
  path_in_repo=path_in_repo,
26
  repo_id=HF_DATASET_REPO,
27
+ token=hf_token, # ← use token from payload
28
  repo_type="dataset"
29
  )
30
 
31
  hf_image_url = f"https://huggingface.co/datasets/{HF_DATASET_REPO}/resolve/main/{path_in_repo}"
32
  return local_tmp_path, hf_image_url, path_in_repo, len(image_bytes)
33
 
34
+
35
  # --- Main MCP function ---
36
  def process_and_describe(payload: dict):
37
  try:
 
44
  image_b64 = payload["image_b64"]
45
 
46
  # 2️⃣ Save image temporarily (for tracking)
47
+ local_tmp_path, hf_url, path_in_repo, size_bytes = save_and_upload_image(image_b64, hf_token)
48
 
49
  # 3️⃣ Initialize HF client per request
50
  hf_client = InferenceClient(token=hf_token)