switch to using gr.LoginButton and update UI accordingly
Browse files
README.md
CHANGED
@@ -9,6 +9,9 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
short_description: 'Build support agent with CrewAI multi-agents and Gradio '
|
|
|
|
|
|
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
short_description: 'Build support agent with CrewAI multi-agents and Gradio '
|
12 |
+
hf_oauth: true
|
13 |
+
hf_oauth_scopes:
|
14 |
+
- read-repos
|
15 |
---
|
16 |
|
17 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -246,19 +246,12 @@ def create_demo():
|
|
246 |
gr.Markdown(
|
247 |
"This is a friendly, high-performing multi-agent application built with Gradio and CrewAI. Enter a webpage URL and your questions from that webpage."
|
248 |
)
|
249 |
-
HF_api_key = gr.Textbox(
|
250 |
-
label="HuggingFace API Key",
|
251 |
-
type="password",
|
252 |
-
placeholder="Type your OpenAI API Key and press Enter to access the app...",
|
253 |
-
interactive=True,
|
254 |
-
)
|
255 |
|
256 |
chatbot = gr.Chatbot(
|
257 |
label="Support Process",
|
258 |
height=700,
|
259 |
type="messages",
|
260 |
show_label=True,
|
261 |
-
visible=False,
|
262 |
avatar_images=(
|
263 |
None,
|
264 |
"https://avatars.githubusercontent.com/u/170677839?v=4",
|
@@ -271,24 +264,25 @@ def create_demo():
|
|
271 |
label="Your Inquiry",
|
272 |
placeholder="Enter your question...",
|
273 |
scale=4,
|
274 |
-
visible=False,
|
275 |
)
|
276 |
website_url = gr.Textbox(
|
277 |
label="Documentation URL",
|
278 |
placeholder="Enter documentation URL to search...",
|
279 |
scale=4,
|
280 |
-
visible=False,
|
281 |
)
|
282 |
-
btn = gr.Button("Get Support", variant="primary", scale=1
|
283 |
|
284 |
-
async def process_input(
|
|
|
|
|
285 |
nonlocal support_crew
|
|
|
286 |
if not api_key:
|
287 |
history = history or []
|
288 |
history.append(
|
289 |
{
|
290 |
"role": "assistant",
|
291 |
-
"content": "Please provide
|
292 |
"metadata": {"title": "❌ Error"},
|
293 |
}
|
294 |
)
|
@@ -323,27 +317,31 @@ def create_demo():
|
|
323 |
)
|
324 |
yield history
|
325 |
|
326 |
-
|
327 |
-
|
328 |
-
HF_api_key: gr.Textbox(visible=False),
|
329 |
-
chatbot: gr.Chatbot(visible=True),
|
330 |
-
inquiry: gr.Textbox(visible=True),
|
331 |
-
website_url: gr.Textbox(visible=True),
|
332 |
-
btn: gr.Button(visible=True),
|
333 |
-
}
|
334 |
-
|
335 |
-
HF_api_key.submit(
|
336 |
-
show_interface, None, [HF_api_key, chatbot, inquiry, website_url, btn]
|
337 |
-
)
|
338 |
-
btn.click(process_input, [inquiry, website_url, chatbot, HF_api_key], [chatbot])
|
339 |
-
inquiry.submit(
|
340 |
-
process_input, [inquiry, website_url, chatbot, HF_api_key], [chatbot]
|
341 |
-
)
|
342 |
|
343 |
return demo
|
344 |
|
345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
if __name__ == "__main__":
|
347 |
-
demo = create_demo()
|
348 |
demo.queue()
|
349 |
-
demo.launch(
|
|
|
246 |
gr.Markdown(
|
247 |
"This is a friendly, high-performing multi-agent application built with Gradio and CrewAI. Enter a webpage URL and your questions from that webpage."
|
248 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
|
250 |
chatbot = gr.Chatbot(
|
251 |
label="Support Process",
|
252 |
height=700,
|
253 |
type="messages",
|
254 |
show_label=True,
|
|
|
255 |
avatar_images=(
|
256 |
None,
|
257 |
"https://avatars.githubusercontent.com/u/170677839?v=4",
|
|
|
264 |
label="Your Inquiry",
|
265 |
placeholder="Enter your question...",
|
266 |
scale=4,
|
|
|
267 |
)
|
268 |
website_url = gr.Textbox(
|
269 |
label="Documentation URL",
|
270 |
placeholder="Enter documentation URL to search...",
|
271 |
scale=4,
|
|
|
272 |
)
|
273 |
+
btn = gr.Button("Get Support", variant="primary", scale=1)
|
274 |
|
275 |
+
async def process_input(
|
276 |
+
inquiry_text, website_url_text, history, oauth_token: gr.OAuthToken | None
|
277 |
+
):
|
278 |
nonlocal support_crew
|
279 |
+
api_key = oauth_token.token
|
280 |
if not api_key:
|
281 |
history = history or []
|
282 |
history.append(
|
283 |
{
|
284 |
"role": "assistant",
|
285 |
+
"content": "Please provide huggingface key.",
|
286 |
"metadata": {"title": "❌ Error"},
|
287 |
}
|
288 |
)
|
|
|
317 |
)
|
318 |
yield history
|
319 |
|
320 |
+
btn.click(process_input, [inquiry, website_url, chatbot], [chatbot])
|
321 |
+
inquiry.submit(process_input, [inquiry, website_url, chatbot], [chatbot])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
|
323 |
return demo
|
324 |
|
325 |
|
326 |
+
def swap_visibilty(profile: gr.OAuthProfile | None):
|
327 |
+
return (
|
328 |
+
gr.update(elem_classes=["main_ui_logged_in"])
|
329 |
+
if profile
|
330 |
+
else gr.update(elem_classes=["main_ui_logged_out"])
|
331 |
+
)
|
332 |
+
|
333 |
+
|
334 |
+
css = """
|
335 |
+
.main_ui_logged_out{opacity: 0.3; pointer-events: none}
|
336 |
+
"""
|
337 |
+
|
338 |
+
interface = create_demo()
|
339 |
+
with gr.Blocks(css=css) as demo:
|
340 |
+
gr.LoginButton()
|
341 |
+
with gr.Column(elem_classes="main_ui_logged_out") as main_ui:
|
342 |
+
interface.render()
|
343 |
+
demo.load(fn=swap_visibilty, outputs=main_ui)
|
344 |
+
|
345 |
if __name__ == "__main__":
|
|
|
346 |
demo.queue()
|
347 |
+
demo.launch()
|