Upload folder using huggingface_hub
Browse filesFiles changed (2)
- app.py+196-19
- requirements.txt-1
123456789101112131415161718192021222324252627282930313233import gradio as grimport requestsMCP_URL = "https://unztspukhwdzrllavnef.supabase.co/functions/v1/mcp"def query_model(prompt, key):if not key.startswith("Bearer "):key = "Bearer " + keyheaders = {"Authorization": key}payload = {"prompt": prompt}try:res = requests.post(MCP_URL, json=payload, headers=headers)res.raise_for_status() # FIX I: surface HTTP errors instead of silently returning themreturn res.textexcept requests.exceptions.HTTPError as e:return f"HTTP error {e.response.status_code}: {e.response.text}"except Exception as e:return str(e)with gr.Blocks() as demo:gr.Markdown("# Gimkit Copilot MCP")key = gr.Textbox(label="API Key (Bearer prefix added automatically)")inp = gr.Textbox(label="Prompt")out = gr.Textbox(label="Output")btn = gr.Button("Run")btn.click(query_model, inputs=[inp, key], outputs=out)demo.launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210import gradio as grimport requestsimport jsonimport timeSB_URL = "https://unztspukhwdzrllavnef.supabase.co"SB_ANON = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVuenRzcHVraHdkenJsbGF2bmVmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzM2MDMzNTAsImV4cCI6MjA4OTE3OTM1MH0.eUWx9O9uX-BqI7oUikVvSAwljgt4Gw3Fl6hb-Xz_YWo"ALL_TOOLS = ["gkc_create_build","gkc_undo_last_build","gkc_get_map_devices","gkc_look_around","gkc_capture_screenshot","gkc_remove_elements","gkc_vc_checkpoint","gkc_list_devices","gkc_search_terrain","gkc_search_props","gkc_get_device_info","gkc_skill_search","gkc_web_search","gkc_wiki_search",]def base_headers():return {"Content-Type": "application/json", "apikey": SB_ANON}def auth_headers(token):return {**base_headers(), "Authorization": "Bearer " + token}# โโ Auth โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโdef sign_in(email, password):if not email.strip() or not password.strip():return None, "โ Enter email and password."try:r = requests.post(SB_URL + "/auth/v1/token?grant_type=password",headers=base_headers(),json={"email": email, "password": password},timeout=10,)d = r.json()if not r.ok:return None, "โ " + (d.get("error_description") or d.get("message") or r.text)return d["access_token"], f"โ Signed in as {d['user']['email']}"except Exception as e:return None, f"โ {e}"def sign_up(email, password):if not email.strip() or not password.strip():return None, "โ Enter email and password."if len(password) < 6:return None, "โ Password must be at least 6 characters."try:r = requests.post(SB_URL + "/auth/v1/signup",headers=base_headers(),json={"email": email, "password": password},timeout=10,)d = r.json()if not r.ok:return None, "โ " + (d.get("error_description") or d.get("message") or r.text)if not d.get("access_token"):return None, "๐ง Check your email to confirm, then sign in."return d["access_token"], f"โ Account created & signed in as {d['user']['email']}"except Exception as e:return None, f"โ {e}"# โโ Tool call (insert row โ poll for result) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโdef call_tool(token, tool_name, args_raw, timeout_s=30):if not token:return "โ Not signed in."try:args = json.loads(args_raw) if args_raw.strip() else {}except json.JSONDecodeError as e:return f"โ Invalid JSON in arguments: {e}"# Insert a pending tool_call rowtry:r = requests.post(SB_URL + "/rest/v1/tool_calls",headers={**auth_headers(token), "Prefer": "return=representation"},json={"name": tool_name, "args": args, "status": "pending"},timeout=10,)r.raise_for_status()row = r.json()[0]row_id = row["id"]except Exception as e:return f"โ Failed to queue tool call: {e}"# Poll until the Gimloader plugin executes it and writes back the resultdeadline = time.time() + timeout_swhile time.time() < deadline:time.sleep(1.2)try:pr = requests.get(SB_URL + f"/rest/v1/tool_calls?id=eq.{row_id}&select=status,result",headers=auth_headers(token),timeout=10,)pr.raise_for_status()rows = pr.json()if not rows:continuerow = rows[0]if row["status"] in ("complete", "error"):result = row["result"]prefix = "โ " if row["status"] == "complete" else "โ "return prefix + json.dumps(result, indent=2)except Exception as e:return f"โ Poll error: {e}"return f"โฑ๏ธ Timed out after {timeout_s}s โ is the Gimloader plugin open and connected in Gimkit?"# โโ Gradio UI โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ_token_state = gr.State(None)with gr.Blocks(title="Gimkit Copilot") as demo:gr.Markdown("# ๐ฎ Gimkit Copilot\nControl your Gimkit Creative map from here.")token_state = gr.State(None)with gr.Tab("Sign In"):gr.Markdown("Sign in or create a free account to get your MCP token.")email_box = gr.Textbox(label="Email", placeholder="you@example.com")pass_box = gr.Textbox(label="Password", placeholder="โขโขโขโขโขโขโขโข", type="password")auth_msg = gr.Textbox(label="Status", interactive=False)with gr.Row():signin_btn = gr.Button("Sign In", variant="primary")signup_btn = gr.Button("Create Account", variant="secondary")def do_signin(email, password, _tok):tok, msg = sign_in(email, password)return tok if tok else _tok, msgdef do_signup(email, password, _tok):tok, msg = sign_up(email, password)return tok if tok else _tok, msgsignin_btn.click(do_signin, inputs=[email_box, pass_box, token_state], outputs=[token_state, auth_msg])signup_btn.click(do_signup, inputs=[email_box, pass_box, token_state], outputs=[token_state, auth_msg])with gr.Tab("Call a Tool"):gr.Markdown("**Requires:** Gimkit Creative open in browser with the GimkitCopilot plugin ""running and showing **โ Connected**.")tool_dd = gr.Dropdown(choices=ALL_TOOLS, value=ALL_TOOLS[0], label="Tool")args_box = gr.Textbox(label='Arguments (JSON)',placeholder='{"devices": [{"type": "textBillboard", "x": 0, "y": 0, "options": {"text": "Hello"}}]}',lines=5,)timeout_sl = gr.Slider(minimum=10, maximum=120, value=30, step=5, label="Timeout (seconds)")call_btn = gr.Button("โถ Run Tool", variant="primary")call_out = gr.Textbox(label="Result", lines=12, interactive=False)call_btn.click(call_tool,inputs=[token_state, tool_dd, args_box, timeout_sl],outputs=call_out,)with gr.Tab("MCP Token"):gr.Markdown("Copy this token into **Claude Desktop**, **Claude Code**, **Cursor**, etc. ""to let your AI client control Gimkit directly.\n\n""**MCP URL:** `https://unztspukhwdzrllavnef.supabase.co/functions/v1/mcp`")tok_box = gr.Textbox(label="Your Bearer Token", interactive=False, type="password")show_btn = gr.Button("๐ Show / Refresh Token")def show_token(tok):if not tok:return "โ Sign in first."return tokshow_btn.click(show_token, inputs=[token_state], outputs=tok_box)gr.Markdown("""### Quick Setup**Claude Desktop** โ add to `claude_desktop_config.json`:```json{"mcpServers": {"gimkit-copilot": {"url": "https://unztspukhwdzrllavnef.supabase.co/functions/v1/mcp","headers": { "Authorization": "Bearer <YOUR-TOKEN>" }}}}```**Claude Code** โ run in terminal:```claude mcp add gimkit-copilot https://unztspukhwdzrllavnef.supabase.co/functions/v1/mcp --header "Authorization: Bearer <YOUR-TOKEN>"```""")demo.launch()
123gradiorequestsbeautifulsoup412gradiorequests
app.py+196-19
requirements.txt-1