Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ from langchain.chains import LLMChain
|
|
| 10 |
from datetime import datetime
|
| 11 |
import pytz
|
| 12 |
import time
|
|
|
|
| 13 |
|
| 14 |
# Get API key from Hugging Face Spaces secrets
|
| 15 |
google_api_key = os.environ.get("GOOGLE_API_KEY")
|
|
@@ -177,6 +178,19 @@ def check_logo_file(logo_path):
|
|
| 177 |
print(f"Files in directory: {os.listdir()}")
|
| 178 |
return os.path.exists(logo_path)
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
# Main function to create and launch the Gradio interface
|
| 181 |
def main():
|
| 182 |
# Initialize retriever
|
|
@@ -223,84 +237,80 @@ def main():
|
|
| 223 |
"""
|
| 224 |
|
| 225 |
logo_path = "Equinix-LOGO.jpeg" # Make sure this file exists in the Space
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
-
# Create Gradio UI
|
| 228 |
-
with gr.Blocks(css=custom_css) as ui:
|
| 229 |
-
# Check if logo exists before creating UI
|
| 230 |
-
logo_exists = check_logo_file(logo_path)
|
| 231 |
-
|
| 232 |
-
# Header with logo
|
| 233 |
-
with gr.Row(elem_id="header-container"):
|
| 234 |
-
with gr.Column():
|
| 235 |
-
if logo_exists:
|
| 236 |
-
# Use HTML for more control over logo display
|
| 237 |
-
gr.HTML(f"""
|
| 238 |
-
<div style="text-align:center;">
|
| 239 |
-
<img id="logo-image" src="file/{logo_path}" alt="Equinix Logo"
|
| 240 |
-
style="max-height:80px; margin:0 auto; display:block;">
|
| 241 |
-
</div>
|
| 242 |
-
""")
|
| 243 |
-
else:
|
| 244 |
-
# Fallback text-based logo
|
| 245 |
-
gr.HTML("""
|
| 246 |
-
<div style="text-align:center; color:white; padding:10px;">
|
| 247 |
-
<div style="color:#FF0000; font-size:24px;">■■■■</div>
|
| 248 |
-
<div style="font-size:28px; letter-spacing:5px; margin-top:5px;">EQUINIX</div>
|
| 249 |
-
</div>
|
| 250 |
-
""")
|
| 251 |
-
|
| 252 |
-
# Title & Description
|
| 253 |
-
gr.Markdown("<h1 style='text-align: center; color: black;'>Equinix Chatbot for Automation Team</h1>")
|
| 254 |
-
|
| 255 |
-
# Date and Time Display
|
| 256 |
-
with gr.Row(elem_classes="datetime-display"):
|
| 257 |
-
date_display = gr.Textbox(label="Date", interactive=False)
|
| 258 |
-
time_display = gr.Textbox(label="Time", interactive=False)
|
| 259 |
-
|
| 260 |
-
# Update date and time initially
|
| 261 |
-
date_val, time_val = get_current_datetime()
|
| 262 |
-
date_display.value = date_val
|
| 263 |
-
time_display.value = time_val
|
| 264 |
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
refresh_btn.click(fn=update_datetime, inputs=[], outputs=[date_display, time_display])
|
| 268 |
|
| 269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
|
| 305 |
if __name__ == "__main__":
|
| 306 |
main()
|
|
|
|
| 10 |
from datetime import datetime
|
| 11 |
import pytz
|
| 12 |
import time
|
| 13 |
+
import shutil
|
| 14 |
|
| 15 |
# Get API key from Hugging Face Spaces secrets
|
| 16 |
google_api_key = os.environ.get("GOOGLE_API_KEY")
|
|
|
|
| 178 |
print(f"Files in directory: {os.listdir()}")
|
| 179 |
return os.path.exists(logo_path)
|
| 180 |
|
| 181 |
+
# In your main function, before creating the UI:
|
| 182 |
+
# Ensure the static directory exists
|
| 183 |
+
os.makedirs("static", exist_ok=True)
|
| 184 |
+
|
| 185 |
+
# Copy the logo file to the static directory (if it's not already there)
|
| 186 |
+
src_logo = "Equinix-LOGO.jpeg"
|
| 187 |
+
dst_logo = os.path.join("static", "Equinix-LOGO.jpeg")
|
| 188 |
+
|
| 189 |
+
if os.path.exists(src_logo) and not os.path.exists(dst_logo):
|
| 190 |
+
shutil.copy(src_logo, dst_logo)
|
| 191 |
+
print(f"Copied logo to {dst_logo}")
|
| 192 |
+
|
| 193 |
+
|
| 194 |
# Main function to create and launch the Gradio interface
|
| 195 |
def main():
|
| 196 |
# Initialize retriever
|
|
|
|
| 237 |
"""
|
| 238 |
|
| 239 |
logo_path = "Equinix-LOGO.jpeg" # Make sure this file exists in the Space
|
| 240 |
+
|
| 241 |
+
# Then in your UI code:
|
| 242 |
+
with gr.Row(elem_id="header-container"):
|
| 243 |
+
with gr.Column():
|
| 244 |
+
if os.path.exists(dst_logo):
|
| 245 |
+
gr.HTML(f"""
|
| 246 |
+
<div style="text-align:center; background-color:black; padding:15px;">
|
| 247 |
+
<img src="/static/Equinix-LOGO.jpeg" alt="Equinix Logo" style="max-height:80px;">
|
| 248 |
+
</div>
|
| 249 |
+
""")
|
| 250 |
+
else:
|
| 251 |
+
# Fallback to text logo
|
| 252 |
+
gr.HTML("""
|
| 253 |
+
<div style="text-align:center; background-color:black; padding:15px;">
|
| 254 |
+
<div style="color:#FF0000; font-size:24px;">■■■■</div>
|
| 255 |
+
<div style="font-size:28px; letter-spacing:5px; margin-top:5px; color:white;">EQUINIX</div>
|
| 256 |
+
</div>
|
| 257 |
+
""")
|
| 258 |
+
|
| 259 |
+
|
| 260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
+
# Title & Description
|
| 263 |
+
gr.Markdown("<h1 style='text-align: center; color: black;'>Equinix Chatbot for Automation Team</h1>")
|
|
|
|
| 264 |
|
| 265 |
+
# Date and Time Display
|
| 266 |
+
with gr.Row(elem_classes="datetime-display"):
|
| 267 |
+
date_display = gr.Textbox(label="Date", interactive=False)
|
| 268 |
+
time_display = gr.Textbox(label="Time", interactive=False)
|
| 269 |
+
|
| 270 |
+
# Update date and time initially
|
| 271 |
+
date_val, time_val = get_current_datetime()
|
| 272 |
+
date_display.value = date_val
|
| 273 |
+
time_display.value = time_val
|
| 274 |
+
|
| 275 |
+
# Add refresh button for time
|
| 276 |
+
refresh_btn = gr.Button("Update Date & Time")
|
| 277 |
+
refresh_btn.click(fn=update_datetime, inputs=[], outputs=[date_display, time_display])
|
| 278 |
+
|
| 279 |
+
gr.Markdown("<p style='text-align: center; color: black;'>Ask me anything!</p>")
|
| 280 |
|
| 281 |
+
# Input & Dropdown Section
|
| 282 |
+
with gr.Row():
|
| 283 |
+
query_input = gr.Textbox(label="Enter your query")
|
| 284 |
+
query_method = gr.Dropdown(["Team Query", "General Query"], label="Select Query Type", value="Team Query")
|
| 285 |
|
| 286 |
+
# Output Textbox
|
| 287 |
+
output_box = gr.Textbox(label="Response", interactive=False)
|
| 288 |
+
|
| 289 |
+
# Buttons Section
|
| 290 |
+
with gr.Row():
|
| 291 |
+
submit_button = gr.Button("Submit")
|
| 292 |
+
reset_button = gr.Button("Reset Query")
|
| 293 |
+
|
| 294 |
+
# Button Click Events
|
| 295 |
+
submit_button.click(
|
| 296 |
+
lambda query, method: query_router(query, method, retriever),
|
| 297 |
+
inputs=[query_input, query_method],
|
| 298 |
+
outputs=output_box
|
| 299 |
+
)
|
| 300 |
|
| 301 |
+
# Reset only the query input
|
| 302 |
+
reset_button.click(reset_query_field, inputs=[], outputs=[query_input,output_box])
|
| 303 |
+
|
| 304 |
|
| 305 |
+
# Update date and time on submission
|
| 306 |
+
submit_button.click(
|
| 307 |
+
fn=update_datetime,
|
| 308 |
+
inputs=[],
|
| 309 |
+
outputs=[date_display, time_display]
|
| 310 |
+
)
|
| 311 |
+
|
| 312 |
+
# Launch UI
|
| 313 |
+
ui.launch(share=True)
|
| 314 |
|
| 315 |
if __name__ == "__main__":
|
| 316 |
main()
|