Spaces:
Running
Running
Update ui/sidebar.py
Browse files- ui/sidebar.py +64 -0
ui/sidebar.py
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Sidebar with Gemini AI chat
|
| 3 |
+
"""
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from chat.gemini import chat_with_gemini, clear_chat
|
| 6 |
+
from config.settings import GEMINI_API_KEY
|
| 7 |
+
|
| 8 |
+
def create_sidebar():
|
| 9 |
+
"""Create the AI chat sidebar"""
|
| 10 |
+
|
| 11 |
+
with gr.Column(elem_classes="sidebar"):
|
| 12 |
+
gr.Markdown("""
|
| 13 |
+
## 🤖 Gemini AI Assistant
|
| 14 |
+
|
| 15 |
+
Ask me anything about web scraping, automation, or get help with using this tool!
|
| 16 |
+
""")
|
| 17 |
+
|
| 18 |
+
if not GEMINI_API_KEY:
|
| 19 |
+
gr.Markdown("""
|
| 20 |
+
⚠️ **Setup Required**: Add your Gemini API key to Hugging Face secrets:
|
| 21 |
+
1. Go to your Space Settings
|
| 22 |
+
2. Add a new secret named `GEMINI_API_KEY`
|
| 23 |
+
3. Get your API key from [Google AI Studio](https://makersuite.google.com/app/apikey)
|
| 24 |
+
""")
|
| 25 |
+
|
| 26 |
+
chatbot = gr.Chatbot(
|
| 27 |
+
value=[],
|
| 28 |
+
elem_classes="chat-container",
|
| 29 |
+
bubble_full_width=False,
|
| 30 |
+
avatar_images=(None, "🤖")
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
msg = gr.Textbox(
|
| 34 |
+
label="Message",
|
| 35 |
+
placeholder="Ask me about web scraping, CSS selectors, or any feature...",
|
| 36 |
+
lines=2
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
with gr.Row():
|
| 40 |
+
submit = gr.Button("Send", variant="primary", scale=1)
|
| 41 |
+
clear = gr.Button("Clear", variant="secondary", scale=1)
|
| 42 |
+
|
| 43 |
+
# Example prompts
|
| 44 |
+
gr.Examples(
|
| 45 |
+
examples=[
|
| 46 |
+
"How do I extract all links from a webpage?",
|
| 47 |
+
"What's the CSS selector for the first paragraph?",
|
| 48 |
+
"How can I handle dynamic content that loads with JavaScript?",
|
| 49 |
+
"Explain the difference between persistent and non-persistent browser",
|
| 50 |
+
"How do I bypass CORS when making API requests?",
|
| 51 |
+
"What's the best way to extract data from a table?",
|
| 52 |
+
"How can I automate form filling and submission?",
|
| 53 |
+
"Help me understand the accessibility audit results"
|
| 54 |
+
],
|
| 55 |
+
inputs=msg,
|
| 56 |
+
label="Example Questions"
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# Chat event handlers
|
| 60 |
+
msg.submit(chat_with_gemini, [msg, chatbot], [msg, chatbot])
|
| 61 |
+
msg.submit(lambda: "", None, msg) # Clear input
|
| 62 |
+
submit.click(chat_with_gemini, [msg, chatbot], [msg, chatbot])
|
| 63 |
+
submit.click(lambda: "", None, msg) # Clear input
|
| 64 |
+
clear.click(clear_chat, None, [msg, chatbot])
|