Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -132,33 +132,36 @@ with gr.Blocks(title="Gemini → HF Space scaffolder") as demo:
|
|
132 |
with gr.Row():
|
133 |
login_btn = gr.LoginButton(
|
134 |
logout_value="Logout ({username})", # label once signed in
|
135 |
-
variant="huggingface",
|
136 |
size="lg"
|
137 |
)
|
138 |
status_md = gr.Markdown("Not logged in")
|
139 |
|
140 |
-
#
|
|
|
|
|
|
|
141 |
def show_profile(profile: gr.OAuthProfile | None):
|
142 |
if profile is None:
|
143 |
-
return
|
144 |
-
return
|
145 |
|
146 |
-
demo.load(show_profile, inputs=None, outputs=status_md)
|
147 |
|
148 |
# -------------------------------------------------------------------------
|
149 |
# Main app controls (hidden behind OAuth)
|
150 |
# -------------------------------------------------------------------------
|
151 |
with gr.Row():
|
152 |
with gr.Column(scale=1):
|
153 |
-
gemini_key
|
154 |
-
hf_user
|
155 |
-
repo_name
|
156 |
-
session_id
|
157 |
-
start_btn
|
158 |
|
159 |
with gr.Column(scale=3):
|
160 |
-
chatbot
|
161 |
-
logs_display
|
162 |
preview_iframe = gr.HTML("<p>No deployed app yet.</p>")
|
163 |
|
164 |
user_msg = gr.Textbox(label="Your message")
|
@@ -169,7 +172,10 @@ with gr.Blocks(title="Gemini → HF Space scaffolder") as demo:
|
|
169 |
# ---------------------------------------------------------------------
|
170 |
def on_start(g_key: str, h_user: str, r_name: str, oauth_token: gr.OAuthToken | None):
|
171 |
if oauth_token is None:
|
172 |
-
return
|
|
|
|
|
|
|
173 |
|
174 |
new_id = str(uuid.uuid4())
|
175 |
state_store[new_id] = start_app(g_key, oauth_token.token, h_user, r_name)
|
@@ -194,7 +200,7 @@ with gr.Blocks(title="Gemini → HF Space scaffolder") as demo:
|
|
194 |
state_store[sess_id] = new_state
|
195 |
|
196 |
chat_history.append((msg, reply))
|
197 |
-
logs
|
198 |
embed = (
|
199 |
f'<iframe src="{new_state["embed_url"]}" width="100%" height="500px"></iframe>'
|
200 |
if new_state.get("embed_url") else ""
|
|
|
132 |
with gr.Row():
|
133 |
login_btn = gr.LoginButton(
|
134 |
logout_value="Logout ({username})", # label once signed in
|
135 |
+
variant="huggingface",
|
136 |
size="lg"
|
137 |
)
|
138 |
status_md = gr.Markdown("Not logged in")
|
139 |
|
140 |
+
# Activate the login button’s routes (silences the warning)
|
141 |
+
login_btn.activate()
|
142 |
+
|
143 |
+
# Callback to refresh the status text whenever OAuth state changes
|
144 |
def show_profile(profile: gr.OAuthProfile | None):
|
145 |
if profile is None:
|
146 |
+
return "*Not logged in.*"
|
147 |
+
return f"Logged in as **{profile.username}**"
|
148 |
|
149 |
+
demo.load(fn=show_profile, inputs=None, outputs=status_md)
|
150 |
|
151 |
# -------------------------------------------------------------------------
|
152 |
# Main app controls (hidden behind OAuth)
|
153 |
# -------------------------------------------------------------------------
|
154 |
with gr.Row():
|
155 |
with gr.Column(scale=1):
|
156 |
+
gemini_key = gr.Textbox(label="Gemini API Key", type="password")
|
157 |
+
hf_user = gr.Textbox(label="HF Username")
|
158 |
+
repo_name = gr.Textbox(label="New App (repo) name")
|
159 |
+
session_id = gr.Textbox(value="", visible=False)
|
160 |
+
start_btn = gr.Button("Start a new app")
|
161 |
|
162 |
with gr.Column(scale=3):
|
163 |
+
chatbot = gr.Chatbot(type="messages")
|
164 |
+
logs_display = gr.Textbox(label="Operation Logs", interactive=False, lines=8)
|
165 |
preview_iframe = gr.HTML("<p>No deployed app yet.</p>")
|
166 |
|
167 |
user_msg = gr.Textbox(label="Your message")
|
|
|
172 |
# ---------------------------------------------------------------------
|
173 |
def on_start(g_key: str, h_user: str, r_name: str, oauth_token: gr.OAuthToken | None):
|
174 |
if oauth_token is None:
|
175 |
+
return (
|
176 |
+
gr.Error("Please *Sign in with Hugging Face* first."),
|
177 |
+
"", "", gr.update(interactive=False)
|
178 |
+
)
|
179 |
|
180 |
new_id = str(uuid.uuid4())
|
181 |
state_store[new_id] = start_app(g_key, oauth_token.token, h_user, r_name)
|
|
|
200 |
state_store[sess_id] = new_state
|
201 |
|
202 |
chat_history.append((msg, reply))
|
203 |
+
logs = "\n".join(new_state["logs"])
|
204 |
embed = (
|
205 |
f'<iframe src="{new_state["embed_url"]}" width="100%" height="500px"></iframe>'
|
206 |
if new_state.get("embed_url") else ""
|