Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,30 +8,30 @@ def handle_request(q: str, user_label: str) -> str:
|
|
| 8 |
return f"[{user_label}] You said: {q}"
|
| 9 |
|
| 10 |
# --- 認証+実行:キーが無いときは guest ---
|
|
|
|
| 11 |
def my_tool(q: str, dev_token: str, request: gr.Request) -> str:
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
if not auth and dev_token:
|
| 17 |
auth = f"Bearer {dev_token.strip()}"
|
| 18 |
-
|
| 19 |
-
# 3) 環境変数(任意の開発用)
|
| 20 |
if not auth:
|
| 21 |
-
|
| 22 |
-
if env_token:
|
| 23 |
-
auth = f"Bearer {env_token}"
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
else:
|
| 29 |
-
token = auth.split(" ", 1)[1].strip()
|
| 30 |
-
short = token[:6] + "..." if len(token) > 6 else token
|
| 31 |
-
user_label = f"user:{short}"
|
| 32 |
|
| 33 |
-
# ここから本来の処理へ
|
| 34 |
-
return handle_request(q, user_label)
|
| 35 |
|
| 36 |
# ---- Gradio UI ----
|
| 37 |
examples = [
|
|
|
|
| 8 |
return f"[{user_label}] You said: {q}"
|
| 9 |
|
| 10 |
# --- 認証+実行:キーが無いときは guest ---
|
| 11 |
+
|
| 12 |
def my_tool(q: str, dev_token: str, request: gr.Request) -> str:
|
| 13 |
+
"""
|
| 14 |
+
Simple demo tool that echoes the user query with authentication context.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
q (str): ユーザーの入力テキスト。
|
| 18 |
+
dev_token (str): 開発・デバッグ用に手動で指定するAPIキー。
|
| 19 |
+
request (gr.Request): HTTPリクエスト。Authorizationヘッダを含む。
|
| 20 |
|
| 21 |
+
Returns:
|
| 22 |
+
str: "guest" または "user:xxxx" と共に入力テキストを返す。
|
| 23 |
+
"""
|
| 24 |
+
# 認証処理は省略(前と同じ)
|
| 25 |
+
auth = request.headers.get("authorization")
|
| 26 |
if not auth and dev_token:
|
| 27 |
auth = f"Bearer {dev_token.strip()}"
|
|
|
|
|
|
|
| 28 |
if not auth:
|
| 29 |
+
return f"[guest] You said: {q}"
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
token = auth.split(" ", 1)[1] if " " in auth else auth
|
| 32 |
+
short = token[:6] + "..." if len(token) > 6 else token
|
| 33 |
+
return f"[user:{short}] You said: {q}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# ---- Gradio UI ----
|
| 37 |
examples = [
|