startrz commited on
Commit
3ff31a7
Β·
verified Β·
1 Parent(s): 980263d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -97
app.py CHANGED
@@ -6,114 +6,48 @@ import time
6
  # Set page configuration as the first Streamlit command
7
  st.set_page_config(page_title="Evo", page_icon="πŸ€–", layout="wide")
8
 
9
- # Advanced CSS for a polished UI
 
 
 
10
  st.markdown("""
11
  <style>
12
- /* Global Styles */
13
- body {
14
- font-family: 'Arial', sans-serif;
15
- background-color: #f5f6fa;
16
- }
17
- .stApp {
18
- background-color: #f5f6fa;
19
- }
20
-
21
- /* Chat Container */
22
  .chat-container {
23
- max-height: 600px;
24
  overflow-y: auto;
25
- border-radius: 15px;
26
- padding: 20px;
27
- background: linear-gradient(135deg, #ffffff, #f0f2f5);
28
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
29
- margin: 20px 0;
30
  }
31
-
32
- /* Messages */
33
  .user-message {
34
- background: #4a90e2;
35
- color: white;
36
- padding: 12px 18px;
37
- border-radius: 15px 15px 0 15px;
38
- margin: 10px 0;
39
- max-width: 70%;
40
- align-self: flex-end;
41
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
42
  }
43
  .assistant-message {
44
- background: #eceff1;
45
- color: #333;
46
- padding: 12px 18px;
47
- border-radius: 15px 15px 15px 0;
48
- margin: 10px 0;
49
- max-width: 70%;
50
- align-self: flex-start;
51
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
52
- }
53
-
54
- /* Sidebar */
55
- .sidebar .sidebar-content {
56
- background: #2c3e50;
57
- color: white;
58
- border-radius: 10px;
59
- padding: 20px;
60
  }
61
  .sidebar-btn {
62
  width: 100%;
63
- margin: 8px 0;
64
- background: #3498db;
65
  color: white;
66
  border: none;
67
- padding: 10px;
68
- border-radius: 8px;
69
  cursor: pointer;
70
- transition: background 0.3s ease;
71
  }
72
  .sidebar-btn:hover {
73
- background: #2980b9;
74
- }
75
-
76
- /* Title and Header */
77
- .title {
78
- font-size: 2.5em;
79
- color: #2c3e50;
80
- text-align: center;
81
- margin-top: 20px;
82
- text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
83
- }
84
- .subtitle {
85
- font-size: 1.2em;
86
- color: #7f8c8d;
87
- text-align: center;
88
- margin-bottom: 30px;
89
- }
90
-
91
- /* Chat Input */
92
- .stTextInput > div > input {
93
- border-radius: 20px;
94
- padding: 10px 15px;
95
- border: 1px solid #dcdcdc;
96
- box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
97
- }
98
-
99
- /* Feedback Buttons */
100
- .feedback-btn {
101
- padding: 5px 10px;
102
- margin: 5px;
103
- border-radius: 50%;
104
- background: #ecf0f1;
105
- cursor: pointer;
106
- transition: transform 0.2s ease;
107
- }
108
- .feedback-btn:hover {
109
- transform: scale(1.1);
110
  }
111
  </style>
112
  """, unsafe_allow_html=True)
113
 
114
- # Define the API endpoint
115
- API_URL = "https://startrz-proagents.hf.space/api/v1/prediction/cce3da9a-f1b9-4bf2-aab8-5462f52ac058"
116
-
117
  # Function to query the API with enhanced error handling
118
  def query(payload):
119
  try:
@@ -129,7 +63,7 @@ def query(payload):
129
  def type_response(text, delay=0.02):
130
  placeholder = st.empty()
131
  for i in range(len(text) + 1):
132
- placeholder.markdown(f'<div class="assistant-message">{text[:i]}</div>', unsafe_allow_html=True)
133
  time.sleep(delay)
134
  return placeholder
135
 
@@ -144,12 +78,12 @@ if 'feedback' not in st.session_state:
144
  st.session_state.feedback = {}
145
 
146
  # Application title and description
147
- st.markdown('<h1 class="title">Evo: Your AI Networking Assistant πŸ€–</h1>', unsafe_allow_html=True)
148
- st.markdown('<p class="subtitle">Explore networking topics with a cutting-edge AI companion</p>', unsafe_allow_html=True)
149
 
150
  # Sidebar with advanced suggested questions
151
  with st.sidebar:
152
- st.markdown('<h2 style="color: white;">Suggested Questions</h2>', unsafe_allow_html=True)
153
  categories = {
154
  "Basics": ["What is TCP/IP?", "How does DNS work?", "What is an IP address?"],
155
  "Advanced": ["Explain VLANs", "What is SD-WAN?", "How does BGP work?"],
@@ -170,17 +104,17 @@ with st.sidebar:
170
  st.markdown('<div class="chat-container">', unsafe_allow_html=True)
171
  for i, message in enumerate(st.session_state.messages):
172
  with st.chat_message(message["role"]):
173
- st.markdown(f'<div class="{message["role"]}-message">**{message["role"].capitalize()} ({message["timestamp"]})**: {message["content"]}</div>', unsafe_allow_html=True)
174
  if message["role"] == "assistant" and i > 0: # Skip initial message
175
  col1, col2 = st.columns([1, 1])
176
  with col1:
177
- if st.button("πŸ‘", key=f"up_{i}", help="Like this response", type="secondary"):
178
  st.session_state.feedback[i] = "positive"
179
  with col2:
180
- if st.button("πŸ‘Ž", key=f"down_{i}", help="Dislike this response", type="secondary"):
181
  st.session_state.feedback[i] = "negative"
182
  if i in st.session_state.feedback:
183
- st markdown(f'<p style="color: #7f8c8d; font-size: 0.9em;">Feedback: {"Liked" if st.session_state.feedback[i] == "positive" else "Disliked"}</p>', unsafe_allow_html=True)
184
  st.markdown('</div>', unsafe_allow_html=True)
185
 
186
  # Function to handle queries (user input or suggestions)
@@ -188,7 +122,7 @@ def handle_query(question):
188
  timestamp = datetime.now().strftime("%H:%M:%S")
189
  st.session_state.messages.append({"role": "user", "content": question, "timestamp": timestamp})
190
  with st.chat_message("user"):
191
- st.markdown(f'<div class="user-message">**User ({timestamp})**: {question}</div>', unsafe_allow_html=True)
192
 
193
  if question in st.session_state.cache:
194
  answer = st.session_state.cache[question]
 
6
  # Set page configuration as the first Streamlit command
7
  st.set_page_config(page_title="Evo", page_icon="πŸ€–", layout="wide")
8
 
9
+ # Define the API endpoint
10
+ API_URL = "https://startrz-proagents.hf.space/api/v1/prediction/cce3da9a-f1b9-4bf2-aab8-5462f52ac058"
11
+
12
+ # Custom CSS for advanced styling
13
  st.markdown("""
14
  <style>
 
 
 
 
 
 
 
 
 
 
15
  .chat-container {
16
+ max-height: 500px;
17
  overflow-y: auto;
18
+ border: 1px solid #e0e0e0;
19
+ border-radius: 10px;
20
+ padding: 10px;
21
+ background-color: #fafafa;
 
22
  }
 
 
23
  .user-message {
24
+ background-color: #d9eaff;
25
+ padding: 10px;
26
+ border-radius: 8px;
27
+ margin: 5px 0;
 
 
 
 
28
  }
29
  .assistant-message {
30
+ background-color: #f0f0f0;
31
+ padding: 10px;
32
+ border-radius: 8px;
33
+ margin: 5px 0;
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
  .sidebar-btn {
36
  width: 100%;
37
+ margin: 5px 0;
38
+ background-color: #4CAF50;
39
  color: white;
40
  border: none;
41
+ padding: 8px;
42
+ border-radius: 5px;
43
  cursor: pointer;
 
44
  }
45
  .sidebar-btn:hover {
46
+ background-color: #45a049;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
48
  </style>
49
  """, unsafe_allow_html=True)
50
 
 
 
 
51
  # Function to query the API with enhanced error handling
52
  def query(payload):
53
  try:
 
63
  def type_response(text, delay=0.02):
64
  placeholder = st.empty()
65
  for i in range(len(text) + 1):
66
+ placeholder.markdown(f"**Assistant**: {text[:i]}")
67
  time.sleep(delay)
68
  return placeholder
69
 
 
78
  st.session_state.feedback = {}
79
 
80
  # Application title and description
81
+ st.title("Evo: Your AI Networking Assistant")
82
+ st.write("Explore networking topics with me! Type your question or click a suggestion below.")
83
 
84
  # Sidebar with advanced suggested questions
85
  with st.sidebar:
86
+ st.header("Suggested Questions")
87
  categories = {
88
  "Basics": ["What is TCP/IP?", "How does DNS work?", "What is an IP address?"],
89
  "Advanced": ["Explain VLANs", "What is SD-WAN?", "How does BGP work?"],
 
104
  st.markdown('<div class="chat-container">', unsafe_allow_html=True)
105
  for i, message in enumerate(st.session_state.messages):
106
  with st.chat_message(message["role"]):
107
+ st.markdown(f"**{message['role'].capitalize()} ({message['timestamp']})**: {message['content']}")
108
  if message["role"] == "assistant" and i > 0: # Skip initial message
109
  col1, col2 = st.columns([1, 1])
110
  with col1:
111
+ if st.button("πŸ‘", key=f"up_{i}", help="Like this response"):
112
  st.session_state.feedback[i] = "positive"
113
  with col2:
114
+ if st.button("πŸ‘Ž", key=f"down_{i}", help="Dislike this response"):
115
  st.session_state.feedback[i] = "negative"
116
  if i in st.session_state.feedback:
117
+ st.write(f"Feedback: {'Liked' if st.session_state.feedback[i] == 'positive' else 'Disliked'}")
118
  st.markdown('</div>', unsafe_allow_html=True)
119
 
120
  # Function to handle queries (user input or suggestions)
 
122
  timestamp = datetime.now().strftime("%H:%M:%S")
123
  st.session_state.messages.append({"role": "user", "content": question, "timestamp": timestamp})
124
  with st.chat_message("user"):
125
+ st.markdown(f"**User ({timestamp})**: {question}")
126
 
127
  if question in st.session_state.cache:
128
  answer = st.session_state.cache[question]