wuhp commited on
Commit
a72fba6
·
verified ·
1 Parent(s): ff16771

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -33,7 +33,6 @@ state_store: Dict[str, Dict[str, Any]] = {}
33
 
34
  def start_app(gemini_key: str, hf_token: str, hf_username: str, repo_name: str) -> Dict[str, Any]:
35
  """Initialise chat with Gemini + create a local workspace for the new app."""
36
-
37
  os.makedirs(WORKSPACE_DIR, exist_ok=True)
38
 
39
  # Gemini client & chat session
@@ -61,7 +60,6 @@ def start_app(gemini_key: str, hf_token: str, hf_username: str, repo_name: str)
61
 
62
  def handle_message(user_msg: str, state: Dict[str, Any]) -> Tuple[str, Dict[str, Any]]:
63
  """Send *user_msg* to Gemini, act on the JSON response, and return assistant reply."""
64
-
65
  chat = state["chat"]
66
  logs = state.setdefault("logs", [])
67
 
@@ -132,12 +130,15 @@ with gr.Blocks(title="Gemini → HF Space scaffolder") as demo:
132
  # OAuth UI row (always visible)
133
  # -------------------------------------------------------------------------
134
  with gr.Row():
135
- login_btn = gr.LoginButton()
136
- logout_btn = gr.LogoutButton()
137
- status_md = gr.Markdown("Not logged in")
 
 
 
138
 
139
  # Callback to refresh the status text whenever the page loads OR OAuth changes
140
- def show_profile(profile: gr.OAuthProfile | None): # automatically injected
141
  if profile is None:
142
  return gr.Markdown.update(value="*Not logged in.*")
143
  return gr.Markdown.update(value=f"Logged in as **{profile.username}**")
@@ -150,14 +151,14 @@ with gr.Blocks(title="Gemini → HF Space scaffolder") as demo:
150
  with gr.Row():
151
  with gr.Column(scale=1):
152
  gemini_key = gr.Textbox(label="Gemini API Key", type="password")
153
- hf_user = gr.Textbox(label="HF Username")
154
- repo_name = gr.Textbox(label="New App (repo) name")
155
  session_id = gr.Textbox(value="", visible=False)
156
- start_btn = gr.Button("Start a new app")
157
 
158
  with gr.Column(scale=3):
159
- chatbot = gr.Chatbot(type="messages")
160
- logs_display = gr.Textbox(label="Operation Logs", interactive=False, lines=8)
161
  preview_iframe = gr.HTML("<p>No deployed app yet.</p>")
162
 
163
  user_msg = gr.Textbox(label="Your message")
@@ -193,7 +194,7 @@ with gr.Blocks(title="Gemini → HF Space scaffolder") as demo:
193
  state_store[sess_id] = new_state
194
 
195
  chat_history.append((msg, reply))
196
- logs = "\n".join(new_state["logs"])
197
  embed = (
198
  f'<iframe src="{new_state["embed_url"]}" width="100%" height="500px"></iframe>'
199
  if new_state.get("embed_url") else ""
 
33
 
34
  def start_app(gemini_key: str, hf_token: str, hf_username: str, repo_name: str) -> Dict[str, Any]:
35
  """Initialise chat with Gemini + create a local workspace for the new app."""
 
36
  os.makedirs(WORKSPACE_DIR, exist_ok=True)
37
 
38
  # Gemini client & chat session
 
60
 
61
  def handle_message(user_msg: str, state: Dict[str, Any]) -> Tuple[str, Dict[str, Any]]:
62
  """Send *user_msg* to Gemini, act on the JSON response, and return assistant reply."""
 
63
  chat = state["chat"]
64
  logs = state.setdefault("logs", [])
65
 
 
130
  # OAuth UI row (always visible)
131
  # -------------------------------------------------------------------------
132
  with gr.Row():
133
+ login_btn = gr.LoginButton(
134
+ logout_value="Logout ({username})", # label once signed in
135
+ variant="huggingface", # optional styling
136
+ size="lg"
137
+ )
138
+ status_md = gr.Markdown("Not logged in")
139
 
140
  # Callback to refresh the status text whenever the page loads OR OAuth changes
141
+ def show_profile(profile: gr.OAuthProfile | None):
142
  if profile is None:
143
  return gr.Markdown.update(value="*Not logged in.*")
144
  return gr.Markdown.update(value=f"Logged in as **{profile.username}**")
 
151
  with gr.Row():
152
  with gr.Column(scale=1):
153
  gemini_key = gr.Textbox(label="Gemini API Key", type="password")
154
+ hf_user = gr.Textbox(label="HF Username")
155
+ repo_name = gr.Textbox(label="New App (repo) name")
156
  session_id = gr.Textbox(value="", visible=False)
157
+ start_btn = gr.Button("Start a new app")
158
 
159
  with gr.Column(scale=3):
160
+ chatbot = gr.Chatbot(type="messages")
161
+ logs_display = gr.Textbox(label="Operation Logs", interactive=False, lines=8)
162
  preview_iframe = gr.HTML("<p>No deployed app yet.</p>")
163
 
164
  user_msg = gr.Textbox(label="Your message")
 
194
  state_store[sess_id] = new_state
195
 
196
  chat_history.append((msg, reply))
197
+ logs = "\n".join(new_state["logs"])
198
  embed = (
199
  f'<iframe src="{new_state["embed_url"]}" width="100%" height="500px"></iframe>'
200
  if new_state.get("embed_url") else ""