OppaAI commited on
Commit
1f8048b
·
verified ·
1 Parent(s): 6210e3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -5
app.py CHANGED
@@ -1,18 +1,45 @@
1
  import os
 
2
  import base64
3
  import requests
 
4
  import secrets
5
  import gradio as gr
6
  from huggingface_hub import upload_file, InferenceClient
7
  from PIL import Image
8
- import json
9
 
10
- # ... (Config and Helper Functions remain the same as previous snippets) ...
11
- # Ensure HF_VLM_MODEL is set back to the Qwen model you want to use:
12
- HF_VLM_MODEL = "Qwen/Qwen2.5-VL-7B-Instruct"
 
 
 
 
 
13
 
14
  # Initialize the Hugging Face Inference Client
15
- hf_client = InferenceClient(token=HF_CV_ROBOT_TOKEN)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # --- Main MCP function ---
18
  def process_and_describe(payload: dict):
 
1
  import os
2
+ import copy
3
  import base64
4
  import requests
5
+ import tempfile
6
  import secrets
7
  import gradio as gr
8
  from huggingface_hub import upload_file, InferenceClient
9
  from PIL import Image
 
10
 
11
+ # --- Config ---
12
+ HF_TOKEN = os.environ.get("HF_CV_ROBOT_TOKEN")
13
+ HF_DATASET_REPO = "OppaAI/Robot_MCP"
14
+ # Model specifically for VLM (image-to-text) tasks on Hugging Face
15
+ HF_VLM_MODEL = "llava-hf/llava-interleave-qwen-0.5b-hf" # A suitable VLM model
16
+
17
+ if not HF_TOKEN:
18
+ raise ValueError("HF_TOKEN environment variable not set.")
19
 
20
  # Initialize the Hugging Face Inference Client
21
+ hf_client = InferenceClient(token=HF_TOKEN)
22
+
23
+ # --- Helper Functions ---
24
+ def save_and_upload_image(image_b64):
25
+ """Save image to /tmp and upload to HF dataset."""
26
+ image_bytes = base64.b64decode(image_b64)
27
+ # Use a unique filename to prevent conflicts in /tmp
28
+ local_tmp_path = f"/tmp/uploaded_image_{secrets.token_hex(8)}.jpg"
29
+ with open(local_tmp_path, "wb") as f:
30
+ f.write(image_bytes)
31
+
32
+ path_in_repo = f"images/uploaded_image_{secrets.token_hex(8)}.jpg"
33
+ upload_file(
34
+ path_or_fileobj=local_tmp_path,
35
+ path_in_repo=path_in_repo,
36
+ repo_id=HF_DATASET_REPO,
37
+ token=HF_TOKEN,
38
+ repo_type="dataset"
39
+ )
40
+
41
+ hf_image_url = f"https://huggingface.co/datasets/{HF_DATASET_REPO}/resolve/main/{path_in_repo}"
42
+ return local_tmp_path, hf_image_url, path_in_repo, len(image_bytes)
43
 
44
  # --- Main MCP function ---
45
  def process_and_describe(payload: dict):