import streamlit as st import requests from datetime import datetime import time # Set page configuration as the first Streamlit command st.set_page_config(page_title="Evo", page_icon="🤖", layout="wide") # Define the API endpoint API_URL = "https://startrz-proagents.hf.space/api/v1/prediction/cce3da9a-f1b9-4bf2-aab8-5462f52ac058" # Custom CSS for advanced styling st.markdown(""" """, unsafe_allow_html=True) # Function to query the API with enhanced error handling def query(payload): try: response = requests.post(API_URL, json=payload, timeout=15) response.raise_for_status() return response.json() except requests.exceptions.Timeout: return {"error": "Request timed out. Please try again later."} except requests.exceptions.RequestException as e: return {"error": f"API error: {str(e)}"} # Simulate typing animation for assistant responses def type_response(text, delay=0.02): placeholder = st.empty() for i in range(len(text) + 1): placeholder.markdown(f"**Assistant**: {text[:i]}") time.sleep(delay) return placeholder # Initialize session state if 'messages' not in st.session_state: st.session_state.messages = [{"role": "assistant", "content": "Hello! I'm Evo, your AI Networking Assistant. How can I assist you today?", "timestamp": datetime.now().strftime("%H:%M:%S")}] if 'cache' not in st.session_state: st.session_state.cache = {} if 'selected_suggestion' not in st.session_state: st.session_state.selected_suggestion = None if 'feedback' not in st.session_state: st.session_state.feedback = {} # Application title and description st.title("Evo: Your AI Networking Assistant") st.write("Explore networking topics with me! Type your question or click a suggestion below.") # Sidebar with advanced suggested questions with st.sidebar: st.header("Suggested Questions") categories = { "Basics": ["What is TCP/IP?", "How does DNS work?", "What is an IP address?"], "Advanced": ["Explain VLANs", "What is SD-WAN?", "How does BGP work?"], "Security": ["What is a firewall?", "How does SSL/TLS work?", "What is zero-trust?"] } for category, questions in categories.items(): with st.expander(category, expanded=True): for q in questions: if st.button(q, key=q, help=f"Click to ask: {q}", on_click=lambda q=q: setattr(st.session_state, 'selected_suggestion', q)): pass if st.button("Clear Conversation", key="clear", help="Reset the chat"): st.session_state.messages = [{"role": "assistant", "content": "Hello! I'm Evo, your AI Networking Assistant. How can I assist you today?", "timestamp": datetime.now().strftime("%H:%M:%S")}] st.session_state.cache = {} st.session_state.feedback = {} st.rerun() # Display chat history with feedback st.markdown('