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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import yfinance as yf
|
3 |
+
import streamlit.components.v1 as components
|
4 |
+
import os
|
5 |
+
from PIL import Image
|
6 |
+
# Set the page layout
|
7 |
+
st.set_page_config(layout="wide")
|
8 |
+
import json
|
9 |
+
import matplotlib.pyplot as plt
|
10 |
+
import numpy as np
|
11 |
+
import base64
|
12 |
+
import pandas as pd
|
13 |
+
import time
|
14 |
+
from transformers import pipeline
|
15 |
+
from dotenv import load_dotenv
|
16 |
+
import os
|
17 |
+
import requests
|
18 |
+
import random
|
19 |
+
|
20 |
+
# Try loading environment variables locally
|
21 |
+
try:
|
22 |
+
from dotenv import load_dotenv
|
23 |
+
load_dotenv()
|
24 |
+
except:
|
25 |
+
pass
|
26 |
+
|
27 |
+
# Get the token from environment variables
|
28 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
29 |
+
|
30 |
+
|
31 |
+
if "framework" not in st.session_state:
|
32 |
+
st.session_state.framework = "gen"
|
33 |
+
# Initialize state
|
34 |
+
if "menu" not in st.session_state:
|
35 |
+
st.session_state.menu = "class"
|
36 |
+
|
37 |
+
if "show_overlay" not in st.session_state:
|
38 |
+
st.session_state.show_overlay = True
|
39 |
+
if "models" not in st.session_state:
|
40 |
+
st.session_state.models = []
|
41 |
+
if "save_path" not in st.session_state:
|
42 |
+
st.session_state.save_path = ""
|
43 |
+
# Initialize message storage
|
44 |
+
if "messages" not in st.session_state:
|
45 |
+
st.session_state.messages = []
|
46 |
+
if "input_text" not in st.session_state:
|
47 |
+
st.session_state.input_text = ""
|
48 |
+
if "input_task" not in st.session_state:
|
49 |
+
st.session_state.input_task = ""
|
50 |
+
if "generate_response" not in st.session_state:
|
51 |
+
st.session_state.generate_response = False
|
52 |
+
|
53 |
+
|
54 |
+
if st.session_state.show_overlay == False:
|
55 |
+
left = -9
|
56 |
+
top = -13
|
57 |
+
else:
|
58 |
+
top= -8
|
59 |
+
left =-5
|
60 |
+
|
61 |
+
# Folder to store chat histories
|
62 |
+
CHAT_DIR = "chat_histories"
|
63 |
+
os.makedirs(CHAT_DIR, exist_ok=True)
|
64 |
+
# Set default chat_id if not set
|
65 |
+
if "chat_id" not in st.session_state:
|
66 |
+
st.session_state.chat_id = "chat_1"
|
67 |
+
# Save messages to a file
|
68 |
+
def save_chat_history():
|
69 |
+
if st.session_state.messages: # Only save if there's at least one message
|
70 |
+
with open(f"{CHAT_DIR}/{st.session_state.chat_id}.json", "w", encoding="utf-8") as f:
|
71 |
+
json.dump(st.session_state.messages, f, ensure_ascii=False, indent=4)
|
72 |
+
#####################################################################################################
|
73 |
+
|
74 |
+
# Function to load data
|
75 |
+
|
76 |
+
def query_huggingface_model(selected_model: dict, input_data, input_type="text",max_new_tokens=512,task="text-classification"):
|
77 |
+
API_URL = selected_model.get("url")
|
78 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
79 |
+
|
80 |
+
try:
|
81 |
+
if input_type == "text":
|
82 |
+
if task == "text-generation":
|
83 |
+
payload = {
|
84 |
+
"messages": [
|
85 |
+
{
|
86 |
+
"role": "user",
|
87 |
+
"content": input_data
|
88 |
+
}
|
89 |
+
],
|
90 |
+
"max_tokens": max_new_tokens,
|
91 |
+
"model":selected_model.get("model")
|
92 |
+
}
|
93 |
+
|
94 |
+
else:
|
95 |
+
payload = {
|
96 |
+
"inputs": input_data ,
|
97 |
+
|
98 |
+
}
|
99 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
100 |
+
|
101 |
+
elif input_type == "image":
|
102 |
+
with open(input_data, "rb") as f:
|
103 |
+
data = f.read()
|
104 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
105 |
+
|
106 |
+
else:
|
107 |
+
return {"error": f"Unsupported input_type: {input_type}"}
|
108 |
+
|
109 |
+
response.raise_for_status()
|
110 |
+
return response.json()
|
111 |
+
|
112 |
+
except requests.exceptions.RequestException as e:
|
113 |
+
return {"error": str(e)}
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
def extract_response_content(response):
|
118 |
+
print(f"Response is: {response}")
|
119 |
+
|
120 |
+
# For text generation or image captioning
|
121 |
+
if isinstance(response, list):
|
122 |
+
if response and isinstance(response[0], dict) and "generated_text" in response[0]:
|
123 |
+
return response[0]["generated_text"]
|
124 |
+
|
125 |
+
elif response and isinstance(response[0], list) and "label" in response[0][0]:
|
126 |
+
# For text classification
|
127 |
+
return [(item["label"], round(item["score"], 3)) for item in response[0]]
|
128 |
+
|
129 |
+
# For OpenAI-style chat responses
|
130 |
+
elif isinstance(response, dict):
|
131 |
+
if "choices" in response and isinstance(response["choices"], list):
|
132 |
+
try:
|
133 |
+
return response["choices"][0]["message"]["content"]
|
134 |
+
except (KeyError, IndexError, TypeError):
|
135 |
+
return "Error: Could not extract message from choices"
|
136 |
+
|
137 |
+
elif "error" in response:
|
138 |
+
return f"Error:Model is temporary unavailable please check your internet connection or try again later"
|
139 |
+
|
140 |
+
return "Unknown response format"
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
# Load a specific chat
|
145 |
+
def load_chat_history(chat_id):
|
146 |
+
file_path = f"{CHAT_DIR}/{chat_id}.json"
|
147 |
+
if os.path.exists(file_path):
|
148 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
149 |
+
st.session_state.messages = json.load(f)
|
150 |
+
st.session_state.chat_id = chat_id
|
151 |
+
else:
|
152 |
+
st.warning(f"No history found for {chat_id}.")
|
153 |
+
st.session_state.show_overlay = False
|
154 |
+
|
155 |
+
st.session_state.models = [
|
156 |
+
{
|
157 |
+
"model": "distilbert-base-uncased-finetuned-sst-2-english",
|
158 |
+
"url": "https://router.huggingface.co/hf-inference/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english"
|
159 |
+
},
|
160 |
+
{
|
161 |
+
"model": "openai-community/roberta-base-openai-detector",
|
162 |
+
"url": "https://router.huggingface.co/hf-inference/models/openai-community/roberta-base-openai-detector"
|
163 |
+
},
|
164 |
+
{
|
165 |
+
"model": "nlptown/bert-base-multilingual-uncased-sentiment",
|
166 |
+
"url": "https://router.huggingface.co/hf-inference/models/nlptown/bert-base-multilingual-uncased-sentiment"
|
167 |
+
},
|
168 |
+
{
|
169 |
+
"model": "BAAI/bge-reranker-base",
|
170 |
+
"url": "https://router.huggingface.co/hf-inference/models/BAAI/bge-reranker-base"
|
171 |
+
},
|
172 |
+
{
|
173 |
+
"model": "SamLowe/roberta-base-go_emotions",
|
174 |
+
"url": "https://router.huggingface.co/hf-inference/models/SamLowe/roberta-base-go_emotions"
|
175 |
+
}
|
176 |
+
]
|
177 |
+
|
178 |
+
if st.session_state.framework == "gen":
|
179 |
+
encoded_logo = "hugging.png"
|
180 |
+
main_bg_ext = "png"
|
181 |
+
main_bg = "picturebg.png "
|
182 |
+
|
183 |
+
|
184 |
+
if st.session_state.framework == "lstm":
|
185 |
+
bg_color = "#FF5733" # For example, a warm red/orange
|
186 |
+
bg_color_iv = "orange" # For example, a warm red/orange
|
187 |
+
text_h1 = "BI-DIRECTIONAL"
|
188 |
+
text_i = "Long short term memory"
|
189 |
+
model = "TENSORFLOW"
|
190 |
+
st.session_state.model = "best_bilstm_model.h5"
|
191 |
+
if st.session_state.framework == "gru":
|
192 |
+
bg_color = "#FF5733" # For example, a warm red/orange
|
193 |
+
bg_color_iv = "orange" # For example, a warm red/orange
|
194 |
+
text_h1 = "GATED RECURRENT UNIT"
|
195 |
+
text_i = "Recurrent Neural Network"
|
196 |
+
model = "TENSORFLOW"
|
197 |
+
st.session_state.model = "best_gru_model.h5"
|
198 |
+
if st.session_state.framework == "gen":
|
199 |
+
bg_color = "#FF5733" # For example, a warm red/orange
|
200 |
+
bg_color_iv = "orange" # For example, a warm red/orange
|
201 |
+
text_h1 = "Amazon Stock Predictor"
|
202 |
+
text_i = "21 Days Ahead of the Market"
|
203 |
+
model = "TENSORFLOW"
|
204 |
+
st.markdown(
|
205 |
+
f"""
|
206 |
+
<style>
|
207 |
+
/* Container for logo and text */
|
208 |
+
/* Container for logo and text */
|
209 |
+
.logo-text-container {{
|
210 |
+
position: fixed;
|
211 |
+
top: 20px; /* Adjust vertical position */
|
212 |
+
left: 30px; /* Align with sidebar */
|
213 |
+
display: flex;
|
214 |
+
align-items: center;
|
215 |
+
gap: 15px;
|
216 |
+
width: 70%;
|
217 |
+
z-index:1000;
|
218 |
+
}}
|
219 |
+
|
220 |
+
/* Logo styling */
|
221 |
+
.logo-text-container img {{
|
222 |
+
width: 60px; /* Adjust logo size */
|
223 |
+
border-radius: 10px; /* Optional: round edges */
|
224 |
+
margin-left:-5px;
|
225 |
+
margin-top: -15px;
|
226 |
+
|
227 |
+
}}
|
228 |
+
|
229 |
+
/* Bold text styling */
|
230 |
+
.logo-text-container h1 {{
|
231 |
+
font-family: Nunito;
|
232 |
+
color: #0175C2;
|
233 |
+
font-size: 25px;
|
234 |
+
font-weight: bold;
|
235 |
+
margin-right :100px;
|
236 |
+
padding:0px;
|
237 |
+
top:0;
|
238 |
+
margin-top: 10px;
|
239 |
+
}}
|
240 |
+
.logo-text-container i{{
|
241 |
+
font-family: Nunito;
|
242 |
+
color: orange;
|
243 |
+
font-size: 15px;
|
244 |
+
margin-right :10px;
|
245 |
+
padding:0px;
|
246 |
+
margin-left:-15.5%;
|
247 |
+
margin-top:2% !important;
|
248 |
+
}}
|
249 |
+
|
250 |
+
/* Sidebar styling */
|
251 |
+
section[data-testid="stSidebar"][aria-expanded="true"] {{
|
252 |
+
margin-top: 100px !important; /* Space for the logo */
|
253 |
+
border-radius: 0 60px 0px 60px !important; /* Top-left and bottom-right corners */
|
254 |
+
width: 300px !important; /* Sidebar width */
|
255 |
+
background: none; /* No background */
|
256 |
+
color: white !important;
|
257 |
+
}}
|
258 |
+
|
259 |
+
header[data-testid="stHeader"] {{
|
260 |
+
background: transparent !important;
|
261 |
+
margin-right: 100px !important;
|
262 |
+
margin-top: 1px !important;
|
263 |
+
z-index: 1 !important;
|
264 |
+
|
265 |
+
color: blue; /* White text */
|
266 |
+
font-family: "Times New Roman " !important; /* Font */
|
267 |
+
font-size: 18px !important; /* Font size */
|
268 |
+
font-weight: bold !important; /* Bold text */
|
269 |
+
padding: 10px 20px; /* Padding for buttons */
|
270 |
+
border: none; /* Remove border */
|
271 |
+
transition: all 0.3s ease-in-out; /* Smooth transition */
|
272 |
+
display: flex;
|
273 |
+
align-items: center;
|
274 |
+
justify-content: center;
|
275 |
+
margin: 10px 0;
|
276 |
+
width:90% !important;
|
277 |
+
left:5.5%;
|
278 |
+
height:60px;
|
279 |
+
margin-top:70px;
|
280 |
+
backdrop-filter: blur(10px);
|
281 |
+
|
282 |
+
}}
|
283 |
+
|
284 |
+
div[data-testid="stDecoration"] {{
|
285 |
+
background-image: none;
|
286 |
+
}}
|
287 |
+
|
288 |
+
div[data-testid="stApp"] {{
|
289 |
+
background: url(data:image/{main_bg_ext};base64,{base64.b64encode(open(main_bg, "rb").read()).decode()});
|
290 |
+
|
291 |
+
background-size: cover; /* Ensure the image covers the full page */
|
292 |
+
background-position: center;
|
293 |
+
background-repeat:no-repeat;
|
294 |
+
height: 98vh;
|
295 |
+
width: 99.3%;
|
296 |
+
border-radius: 20px !important;
|
297 |
+
margin-left: 5px;
|
298 |
+
margin-right: 20px;
|
299 |
+
margin-top: 10px;
|
300 |
+
overflow: hidden;
|
301 |
+
backdrop-filter: blur(10px); /* Glass effect */
|
302 |
+
-webkit-backdrop-filter: blur(10px);
|
303 |
+
border: 1px solid rgba(255, 255, 255, 0.2); /* Light border */
|
304 |
+
|
305 |
+
|
306 |
+
}}
|
307 |
+
|
308 |
+
|
309 |
+
section[data-testid="stMain"] {{
|
310 |
+
overflow:hidden !important;
|
311 |
+
|
312 |
+
}}
|
313 |
+
|
314 |
+
div[data-testid="stSlider"] {{
|
315 |
+
margin-top:45px;
|
316 |
+
}}
|
317 |
+
label[data-testid="stWidgetLabel"]{{
|
318 |
+
margin-left:20px !important;
|
319 |
+
}}
|
320 |
+
|
321 |
+
div[data-baseweb="slider"] {{
|
322 |
+
border-radius: 30px;
|
323 |
+
padding-right:40px;
|
324 |
+
z-index: 1;
|
325 |
+
/* Glass effect background */
|
326 |
+
backdrop-filter: blur(2px);
|
327 |
+
-webkit-backdrop-filter: blur(12px);
|
328 |
+
/* Shiny blue borders (left & right) */
|
329 |
+
border-top: 2px solid rgba(255, 255, 155, 0.4); /* Light border */
|
330 |
+
margin-left:13px;
|
331 |
+
border-bottom: 2px solid rgba(255, 255, 155, 0.4); /* Light border */
|
332 |
+
|
333 |
+
|
334 |
+
}}
|
335 |
+
div[data-baseweb="slider"] > :nth-child(1)> div {{
|
336 |
+
margin-left:20px !important;
|
337 |
+
margin-top:10px;
|
338 |
+
}}
|
339 |
+
div[data-testid="stSliderTickBarMin"]{{
|
340 |
+
background:none !important;
|
341 |
+
margin-left:20px !important;
|
342 |
+
font-size:12px;
|
343 |
+
margin-bottom:5px;
|
344 |
+
font-family: "Times New Roman " !important; /* Font */
|
345 |
+
}}
|
346 |
+
div[data-testid="stSliderTickBarMax"]{{
|
347 |
+
background:none !important;
|
348 |
+
font-size:12px;
|
349 |
+
margin-bottom:5px;
|
350 |
+
|
351 |
+
font-family: "Times New Roman " !important; /* Font */
|
352 |
+
}}
|
353 |
+
div[data-testid="stSliderThumbValue"]{{
|
354 |
+
font-size:12px;
|
355 |
+
font-family: "Times New Roman " !important; /* Font */
|
356 |
+
|
357 |
+
}}
|
358 |
+
div[data-testid="stProgress"]{{
|
359 |
+
margin-right:25px;
|
360 |
+
margin-top:-70px;
|
361 |
+
height:10px !important;
|
362 |
+
|
363 |
+
}}
|
364 |
+
[class*="st-key-content-container-3"] {{
|
365 |
+
margin-top: 50px; /* Adjust top margin */
|
366 |
+
margin-left:550px !important;
|
367 |
+
color:orange;
|
368 |
+
font-size:2.2rem;
|
369 |
+
|
370 |
+
}}
|
371 |
+
|
372 |
+
/* Button row styling */
|
373 |
+
.button-row {{
|
374 |
+
display: flex;
|
375 |
+
justify-content: flex-start;
|
376 |
+
gap: 20px;
|
377 |
+
margin-bottom: 20px;
|
378 |
+
}}
|
379 |
+
|
380 |
+
|
381 |
+
|
382 |
+
.custom-button:hover {{
|
383 |
+
background-color: #0056b3;
|
384 |
+
}}
|
385 |
+
div.stButton > button p{{
|
386 |
+
color: orange !important;
|
387 |
+
font-weight:bold;
|
388 |
+
}}
|
389 |
+
div.stButton > button {{
|
390 |
+
color: orange !important; /* White text */
|
391 |
+
font-family: "Times New Roman " !important; /* Font */
|
392 |
+
font-size: 18px !important; /* Font size */
|
393 |
+
font-weight: bold !important; /* Bold text */
|
394 |
+
padding: 10px 20px; /* Padding for buttons */
|
395 |
+
border: none; /* Remove border */
|
396 |
+
border-radius: 35px; /* Rounded corners */
|
397 |
+
transition: all 0.3s ease-in-out; /* Smooth transition */
|
398 |
+
display: flex;
|
399 |
+
align-items: center;
|
400 |
+
transform: scale(1.05); /* Slightly enlarge button */
|
401 |
+
transform: scale(1.1); /* Slight zoom on hover */
|
402 |
+
justify-content: center;
|
403 |
+
|
404 |
+
|
405 |
+
|
406 |
+
}}
|
407 |
+
|
408 |
+
/* Hover effect */
|
409 |
+
div.stButton > button:hover {{
|
410 |
+
background: rgba(255, 255, 255, 0.2);
|
411 |
+
box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.4); /* Enhanced shadow on hover */
|
412 |
+
transform: scale(1.05); /* Slightly enlarge button */
|
413 |
+
transform: scale(1.1); /* Slight zoom on hover */
|
414 |
+
box-shadow: 0px 4px 12px rgba(255, 255, 255, 0.4); /* Glow effect */
|
415 |
+
}}
|
416 |
+
|
417 |
+
div[data-testid="stMarkdownContainer"] p {{
|
418 |
+
font-family: "Times New Roman" !important; /* Elegant font for title */
|
419 |
+
color:black !important;
|
420 |
+
|
421 |
+
}}
|
422 |
+
.titles{{
|
423 |
+
margin-top:-90px !important;
|
424 |
+
margin-left:40px;
|
425 |
+
text-align:center;
|
426 |
+
align-items:center;
|
427 |
+
|
428 |
+
font-family: "Times New Roman" !important;
|
429 |
+
|
430 |
+
}}
|
431 |
+
.header {{
|
432 |
+
align-items: center;
|
433 |
+
gap: 20px; /* Optional: adds space between image and text */
|
434 |
+
}}
|
435 |
+
|
436 |
+
/* Title styling */
|
437 |
+
.header h1{{
|
438 |
+
font-size: 5rem;
|
439 |
+
font-weight: bold;
|
440 |
+
margin-left: 5px;
|
441 |
+
/* margin-top:-50px;*/
|
442 |
+
margin-bottom:30px;
|
443 |
+
padding: 0;
|
444 |
+
color: black; /* Neutral color for text */
|
445 |
+
}}
|
446 |
+
.header h1 span{{
|
447 |
+
font-size: 6rem;
|
448 |
+
font-weight: bold;
|
449 |
+
margin-left: 5px;
|
450 |
+
/* margin-top:-50px;*/
|
451 |
+
margin-bottom:30px;
|
452 |
+
background: orange;
|
453 |
+
padding:5px;
|
454 |
+
border-radius:15px ;
|
455 |
+
color: black; /* Neutral color for text */
|
456 |
+
}}
|
457 |
+
.titles .content{{
|
458 |
+
font-family: "Times New Roman" !important; /* Elegant font for title */
|
459 |
+
font-size: 1.1rem;
|
460 |
+
margin-bottom:1px;
|
461 |
+
padding: 0;
|
462 |
+
color:black; /* Neutral color for text */
|
463 |
+
}}
|
464 |
+
|
465 |
+
|
466 |
+
|
467 |
+
</style>
|
468 |
+
|
469 |
+
""",
|
470 |
+
unsafe_allow_html=True,
|
471 |
+
)
|
472 |
+
# Overlay container
|
473 |
+
st.markdown(
|
474 |
+
f"""
|
475 |
+
<style>
|
476 |
+
.logo-text-containers {{
|
477 |
+
position: absolute;
|
478 |
+
top: -60px;
|
479 |
+
right: 40px;
|
480 |
+
background-color: rgba(255, 255, 255, 0.9);
|
481 |
+
padding: 15px;
|
482 |
+
border-radius: 12px;
|
483 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
484 |
+
z-index: 10;
|
485 |
+
width:80vw;
|
486 |
+
height:620px;
|
487 |
+
}}
|
488 |
+
.logo-text-containers img {{
|
489 |
+
height: 40px;
|
490 |
+
right:0;
|
491 |
+
}}
|
492 |
+
.logo-text-containers h1 {{
|
493 |
+
display: inline;
|
494 |
+
font-size: 20px;
|
495 |
+
vertical-align: middle;
|
496 |
+
}}
|
497 |
+
.logo-text-containers i {{
|
498 |
+
display: block;
|
499 |
+
margin-top: 5px;
|
500 |
+
font-size: 14px;
|
501 |
+
color: #333;
|
502 |
+
}}
|
503 |
+
|
504 |
+
div[class*="st-key-try"] >div>button > div >p{{
|
505 |
+
top: 5px;
|
506 |
+
font-size: 30px !important;
|
507 |
+
font-weight: bold !important;
|
508 |
+
cursor: pointer;
|
509 |
+
color:orange !important;
|
510 |
+
z-index:1000;
|
511 |
+
}}
|
512 |
+
div[class*="st-key-try"] >div>button {{
|
513 |
+
height:70px !important;
|
514 |
+
width:250px !important;
|
515 |
+
}}
|
516 |
+
[class*="st-key-close-btn"]:hover {{
|
517 |
+
color: #f00;
|
518 |
+
}}
|
519 |
+
[class*="st-key-divider-col"] {{
|
520 |
+
border-left: 3px solid rgba(255, 255, 155, 0.5); /* Light border */
|
521 |
+
border-radius: 35px; /* Rounded corners */
|
522 |
+
margin-top:-15px;
|
523 |
+
margin-left:3px;
|
524 |
+
|
525 |
+
}}
|
526 |
+
[class*="st-key-col1"] {{
|
527 |
+
border-right: 3px solid rgba(255, 255, 155, 0.5); /* Light border */
|
528 |
+
border-radius: 35px; /* Rounded corners */
|
529 |
+
margin-left:20px;
|
530 |
+
margin-top:-15px;
|
531 |
+
|
532 |
+
}}
|
533 |
+
|
534 |
+
[class*="st-key-logo-text-containers"] {{
|
535 |
+
margin: 10px; /* Set a margin inside the container */
|
536 |
+
max-width: 100%;
|
537 |
+
overflow: hidden;
|
538 |
+
|
539 |
+
position: absolute;
|
540 |
+
top:-43px;
|
541 |
+
left:10px;
|
542 |
+
overflow: hidden;
|
543 |
+
background-color: tansparent;
|
544 |
+
padding: 15px;
|
545 |
+
border-radius: 30px;
|
546 |
+
padding-right:40px;
|
547 |
+
z-index: 1;
|
548 |
+
width:88vw;
|
549 |
+
height:660px;
|
550 |
+
/* Glass effect background */
|
551 |
+
background: rgba(255, 255, 255, 0.15);
|
552 |
+
backdrop-filter: blur(12px);
|
553 |
+
-webkit-backdrop-filter: blur(12px);
|
554 |
+
/* Shiny blue borders (left & right) */
|
555 |
+
border-left: 3px solid rgba(255, 255, 255, 0.9); /* Light border */
|
556 |
+
border-right: 3px solid rgba(255, 255, 255, 0.9); /* Light border */
|
557 |
+
|
558 |
+
|
559 |
+
}}
|
560 |
+
|
561 |
+
@media (max-width: 768px) {{
|
562 |
+
.logo-text-container h1 {{
|
563 |
+
font-size: 12px;
|
564 |
+
|
565 |
+
}}
|
566 |
+
.logo-text-container i {{
|
567 |
+
font-size: 10px;
|
568 |
+
ma
|
569 |
+
}}
|
570 |
+
|
571 |
+
|
572 |
+
.logo-text-container img {{
|
573 |
+
width: 30px; /* Adjust logo size */
|
574 |
+
border-radius: 10px; /* Optional: round edges */
|
575 |
+
margin-left:15px;
|
576 |
+
margin-top: -35px;
|
577 |
+
|
578 |
+
}}
|
579 |
+
|
580 |
+
}}
|
581 |
+
</style>
|
582 |
+
""",
|
583 |
+
unsafe_allow_html=True,
|
584 |
+
)
|
585 |
+
|
586 |
+
|
587 |
+
st.markdown(
|
588 |
+
f""" <div class="logo-text-container">
|
589 |
+
<img src="data:image/png;base64,{base64.b64encode(open("hugging.png","rb").read()).decode()}" alt="Uploaded Image">
|
590 |
+
<h1>Hugging face<br></h1>
|
591 |
+
<i>transformers pipeline</i>
|
592 |
+
</div>
|
593 |
+
|
594 |
+
""",
|
595 |
+
unsafe_allow_html=True,
|
596 |
+
)
|
597 |
+
|
598 |
+
|
599 |
+
st.markdown(
|
600 |
+
f""" <div class="titles">
|
601 |
+
<div class = "header">
|
602 |
+
<h1></br><span>Frame the </span> Prompt </br> Where Words Become Art
|
603 |
+
</h1>
|
604 |
+
</div>
|
605 |
+
<div class="content">
|
606 |
+
This intelligent assistant enables you to generate insightful text and vivid imagery from simple prompts.
|
607 |
+
Whether you're brainstorming ideas, <br>drafting content, or visualizing concepts — everything is saved, so your creative flow never skips a beat.
|
608 |
+
</div>
|
609 |
+
</div>
|
610 |
+
""",
|
611 |
+
unsafe_allow_html=True,
|
612 |
+
)
|
613 |
+
|
614 |
+
|
615 |
+
with st.container(key="content-container-3"):
|
616 |
+
if st.button("Try it now ",key="try"):
|
617 |
+
st.session_state.framework = "dash"
|
618 |
+
st.session_state.show_overlay = True
|
619 |
+
st.rerun()
|
620 |
+
|
621 |
+
if st.session_state.framework == "dash":
|
622 |
+
if st.session_state.menu == "class":
|
623 |
+
choice1 = 'Classify this email as "Spam" or "Not Spam": "Win a vacation to the Bahamas! Click the link below to claim your prize."'
|
624 |
+
choice2 = 'Is the following tweet "Positive", "Negative", or "Neutral"? "Can’t believe my phone just died right before an important call. Ugh!"'
|
625 |
+
choice3 = 'Categorize this news headline: "Apple unveils new AI chip in latest iPhone" Categories: Technology, Sports, Health, Politics'
|
626 |
+
choice4 = 'Assign a topic label to this sentence: "I made a delicious homemade lasagna last night." Options: Food, Travel, Finance, Education'
|
627 |
+
text_h1 = "🏷️ Text Classification"
|
628 |
+
images="images.png"
|
629 |
+
images="images.png"
|
630 |
+
image1 = 'images.png'
|
631 |
+
image2 = 'images.png'
|
632 |
+
image3 = 'images.png'
|
633 |
+
margin = 0
|
634 |
+
margintop = "-20"
|
635 |
+
st.session_state.models = [
|
636 |
+
{
|
637 |
+
"model": "distilbert-base-uncased-finetuned-sst-2-english",
|
638 |
+
"url": "https://router.huggingface.co/hf-inference/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english"
|
639 |
+
},
|
640 |
+
{
|
641 |
+
"model": "openai-community/roberta-base-openai-detector",
|
642 |
+
"url": "https://router.huggingface.co/hf-inference/models/openai-community/roberta-base-openai-detector"
|
643 |
+
},
|
644 |
+
{
|
645 |
+
"model": "nlptown/bert-base-multilingual-uncased-sentiment",
|
646 |
+
"url": "https://router.huggingface.co/hf-inference/models/nlptown/bert-base-multilingual-uncased-sentiment"
|
647 |
+
},
|
648 |
+
{
|
649 |
+
"model": "BAAI/bge-reranker-base",
|
650 |
+
"url": "https://router.huggingface.co/hf-inference/models/BAAI/bge-reranker-base"
|
651 |
+
},
|
652 |
+
{
|
653 |
+
"model": "SamLowe/roberta-base-go_emotions",
|
654 |
+
"url": "https://router.huggingface.co/hf-inference/models/SamLowe/roberta-base-go_emotions"
|
655 |
+
}
|
656 |
+
]
|
657 |
+
|
658 |
+
task = "text-classification"
|
659 |
+
st.session_state.model = "best_bilstm_model.h5"
|
660 |
+
if st.session_state.menu == "gen":
|
661 |
+
choice1 = 'Write a poem about the ocean at night. Include imagery and emotion to bring it to life.'
|
662 |
+
choice2 = 'Generate a product description for a futuristic smartwatch with health monitoring features.'
|
663 |
+
choice3 = 'Complete this sentence: "As she opened the old journal, she found..."'
|
664 |
+
choice4 = 'Write a motivational quote that could be used in a fitness app.'
|
665 |
+
text_h1 = "✍️ Text Generation"
|
666 |
+
images="images.png"
|
667 |
+
image1 = 'images.png'
|
668 |
+
image2 = 'images.png'
|
669 |
+
image3 = 'images.png'
|
670 |
+
margin = 0
|
671 |
+
margintop = -20
|
672 |
+
task = "text-generation"
|
673 |
+
st.session_state.models = [
|
674 |
+
{
|
675 |
+
"model": "deepseek-ai/DeepSeek-V3",
|
676 |
+
"url": "https://router.huggingface.co/nebius/v1/chat/completions"
|
677 |
+
},
|
678 |
+
{
|
679 |
+
"model": "mistralai/mistral-7b-instruct",
|
680 |
+
"url": "https://router.huggingface.co/novita/v3/openai/chat/completions"
|
681 |
+
},
|
682 |
+
{
|
683 |
+
"model": "meta-llama/llama-3.1-8b-instruct",
|
684 |
+
"url":"https://router.huggingface.co/novita/v3/openai/chat/completions"
|
685 |
+
},
|
686 |
+
{
|
687 |
+
"model": "qwen/qwq-32b",
|
688 |
+
"url": "https://router.huggingface.co/novita/v3/openai/chat/completions"
|
689 |
+
},
|
690 |
+
{
|
691 |
+
"model": "google/gemma-2-2b-it-fast",
|
692 |
+
"url": "https://router.huggingface.co/nebius/v1/chat/completions"
|
693 |
+
}
|
694 |
+
]
|
695 |
+
st.session_state.model = "best_bilstm_model.h5"
|
696 |
+
if st.session_state.menu == "image":
|
697 |
+
choice1 = ''
|
698 |
+
choice2 = ''
|
699 |
+
choice3 = ''
|
700 |
+
choice4 = ''
|
701 |
+
text_h1 = "🖼️ Image to Text "
|
702 |
+
images = 'images.jfif'
|
703 |
+
image1 = 'logo2.png'
|
704 |
+
image2 = 'hugging.png'
|
705 |
+
margintop = -90
|
706 |
+
image3 = 'Captured.png'
|
707 |
+
st.session_state.models = [
|
708 |
+
{
|
709 |
+
"model": "Salesforce/blip-image-captioning-large",
|
710 |
+
"url": "https://router.huggingface.co/hf-inference/models/Salesforce/blip-image-captioning-large"
|
711 |
+
},
|
712 |
+
{
|
713 |
+
"model": "nlpconnect/vit-gpt2-image-captioning",
|
714 |
+
"url": "https://router.huggingface.co/hf-inference/models/nlpconnect/vit-gpt2-image-captioning"
|
715 |
+
}
|
716 |
+
]
|
717 |
+
task = "image-to-text"
|
718 |
+
|
719 |
+
margin = 120
|
720 |
+
st.session_state.model = "best_bilstm_model.h5"
|
721 |
+
st.markdown(
|
722 |
+
"""
|
723 |
+
<style>
|
724 |
+
section[data-testid="stSidebar"] {
|
725 |
+
scrollbar-width: thin;
|
726 |
+
scrollbar-color: #888 #f1f1f1;
|
727 |
+
}
|
728 |
+
section[data-testid="stSidebar"] ::-webkit-scrollbar {
|
729 |
+
width: 4px;
|
730 |
+
}
|
731 |
+
section[data-testid="stSidebar"] ::-webkit-scrollbar-thumb {
|
732 |
+
background-color: #888;
|
733 |
+
border-radius: 10px;
|
734 |
+
}
|
735 |
+
</style>
|
736 |
+
""",
|
737 |
+
unsafe_allow_html=True
|
738 |
+
)
|
739 |
+
|
740 |
+
st.markdown(
|
741 |
+
f"""
|
742 |
+
<style>
|
743 |
+
/* Sidebar styling */
|
744 |
+
section[data-testid="stSidebar"][aria-expanded="true"] {{
|
745 |
+
margin-top: 0px !important; /* Space for the logo */
|
746 |
+
width: 300px !important; /* Sidebar width */
|
747 |
+
/* box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2); /* Shadow effect */
|
748 |
+
/* border: 1px solid #FFD700; /* Shiny golden border */
|
749 |
+
margin-bottom: 1px !important;
|
750 |
+
color:white !important;
|
751 |
+
white-space: nowrap;
|
752 |
+
overflow: hidden;
|
753 |
+
text-overflow: ellipsis;
|
754 |
+
|
755 |
+
background:#f9f9f9;
|
756 |
+
|
757 |
+
}}
|
758 |
+
*, html {{scroll-behavior: smooth !important;}}
|
759 |
+
|
760 |
+
div[data-testid="stSidebarContent"]{{
|
761 |
+
overflow-x:hidden !important;
|
762 |
+
|
763 |
+
|
764 |
+
}}
|
765 |
+
/* Style for the upload button */
|
766 |
+
[class*="st-key-upload-btn"] {{
|
767 |
+
top: -31px; /* Position from the top of the inner circle */
|
768 |
+
left: 150px; /* Position horizontally at the center */
|
769 |
+
padding: 10px 20px;
|
770 |
+
color: red;
|
771 |
+
border: none;
|
772 |
+
border-radius: 15px;
|
773 |
+
cursor: pointer;
|
774 |
+
font-size: 35px !important;
|
775 |
+
z-index:10000000;
|
776 |
+
width:300px;
|
777 |
+
}}
|
778 |
+
[class*="st-key-upload-btns"] {{
|
779 |
+
top: 106px; /* Position from the top of the inner circle */
|
780 |
+
left: 390px; /* Position horizontally at the center */
|
781 |
+
padding: 10px 20px;
|
782 |
+
color: red;
|
783 |
+
border: none;
|
784 |
+
border-radius: 10px;
|
785 |
+
cursor: pointer;
|
786 |
+
font-size: 35px !important;
|
787 |
+
z-index:10000000000000000000000;
|
788 |
+
width:300px;
|
789 |
+
}}
|
790 |
+
|
791 |
+
.upload-btn:hover {{
|
792 |
+
background-color: rgba(0, 123, 255, 1);
|
793 |
+
}}
|
794 |
+
div[data-testid="stFileUploader"] label > div > p {{
|
795 |
+
display:none;
|
796 |
+
color:white !important;
|
797 |
+
}}
|
798 |
+
div[data-testid="stFileUploader"] > div {{
|
799 |
+
color:blue !important;
|
800 |
+
margin-top:-110px;
|
801 |
+
margin-left:150px;
|
802 |
+
width:300px;
|
803 |
+
height:110px;
|
804 |
+
}}
|
805 |
+
|
806 |
+
section[data-testid="stFileUploaderDropzone"] {{
|
807 |
+
width:900px;
|
808 |
+
height: 120px;
|
809 |
+
border-radius: 30px;
|
810 |
+
display: flex;
|
811 |
+
justify-content: center;
|
812 |
+
align-items: center;
|
813 |
+
margin-top:-10px;
|
814 |
+
margin:20px;
|
815 |
+
background-color:#f0f2f6; /* Transparent blue background */
|
816 |
+
color:white;
|
817 |
+
}}
|
818 |
+
div[data-testid="stFileUploaderDropzoneInstructions"] div > small{{
|
819 |
+
color:white !important;
|
820 |
+
display:none;
|
821 |
+
}}
|
822 |
+
div[data-testid="stFileUploaderDropzoneInstructions"] span{{
|
823 |
+
margin-left:65px;
|
824 |
+
color:black;
|
825 |
+
}}
|
826 |
+
div[data-testid="stFileUploaderDropzoneInstructions"] div{{
|
827 |
+
display:none;
|
828 |
+
}}
|
829 |
+
section[data-testid="stFileUploaderDropzone"] button{{
|
830 |
+
display:none;
|
831 |
+
}}
|
832 |
+
|
833 |
+
div[data-testid="stMarkdownContainer"] p {{
|
834 |
+
font-family: "Times New Roman" !important; /* Elegant font for title */
|
835 |
+
color:black !important;
|
836 |
+
}}
|
837 |
+
div[class*="st-key-user-"]{{
|
838 |
+
margin-left:500px;
|
839 |
+
width:550px;
|
840 |
+
|
841 |
+
}}
|
842 |
+
div[class*="st-key-assistant-"]{{
|
843 |
+
margin-left:120px;
|
844 |
+
|
845 |
+
}}
|
846 |
+
|
847 |
+
.highlight {{
|
848 |
+
border: 4px solid lime;
|
849 |
+
font-weight: bold;
|
850 |
+
background: radial-gradient(circle, rgba(0,255,0,0.3) 0%, rgba(0,0,0,0) 70%);
|
851 |
+
box-shadow: 0px 0px 30px 10px rgba(0, 255, 0, 0.9),
|
852 |
+
0px 0px 60px 20px rgba(0, 255, 0, 0.6),
|
853 |
+
inset 0px 0px 15px rgba(0, 255, 0, 0.8);
|
854 |
+
transition: all 0.3s ease-in-out;
|
855 |
+
|
856 |
+
}}
|
857 |
+
.highlight:hover {{
|
858 |
+
transform: scale(1.05);
|
859 |
+
background: radial-gradient(circle, rgba(0,255,0,0.6) 0%, rgba(0,0,0,0) 80%);
|
860 |
+
box-shadow: 0px 0px 40px 15px rgba(0, 255, 0, 1),
|
861 |
+
0px 0px 70px 30px rgba(0, 255, 0, 0.7),
|
862 |
+
inset 0px 0px 20px rgba(0, 255, 0, 1);
|
863 |
+
}}
|
864 |
+
header[data-testid="stHeader"] {{
|
865 |
+
/* border-radius: 1px !important;*/
|
866 |
+
background: white !important; /* Gradient background */
|
867 |
+
/*: 3px solid #FFD700; /* Shiny golden border */
|
868 |
+
/*border-bottom:none !important;*/
|
869 |
+
margin-right: 300px !important;
|
870 |
+
margin-top: 12.5px !important;
|
871 |
+
z-index: 11 !important; /* Ensure it stays above other elements */
|
872 |
+
border-bottom:1px solid #ccc;
|
873 |
+
width:64%;
|
874 |
+
height:85px;
|
875 |
+
margin-left:530px;
|
876 |
+
|
877 |
+
|
878 |
+
}}
|
879 |
+
div[data-testid="stDecoration"]{{
|
880 |
+
background-image:none;
|
881 |
+
}}
|
882 |
+
button[data-testid="stBaseButton-secondary"]{{
|
883 |
+
background:transparent;
|
884 |
+
border:none;
|
885 |
+
}}
|
886 |
+
div[data-testid="stApp"]{{
|
887 |
+
background:#f5f3f0;
|
888 |
+
height: 98.9vh; /* Full viewport height */
|
889 |
+
width: 99%;
|
890 |
+
border-radius: 10px !important;
|
891 |
+
margin-left:5px;
|
892 |
+
margin-right:10px;
|
893 |
+
margin-top:5px;
|
894 |
+
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
|
895 |
+
|
896 |
+
overflow: hidden;
|
897 |
+
|
898 |
+
}}
|
899 |
+
div[data-testid="stChatMessage"]{{
|
900 |
+
z-index:1;
|
901 |
+
border-radius:50px;
|
902 |
+
|
903 |
+
|
904 |
+
}}
|
905 |
+
section[data-testid="stAppScrollToBottomContainer"]{{
|
906 |
+
margin-top:80px !important;
|
907 |
+
padding-right:50px !important;
|
908 |
+
}}
|
909 |
+
div[data-testid="stChatMessageAvatarUser"]{{
|
910 |
+
display:none;
|
911 |
+
}}
|
912 |
+
div[data-testid="stChatMessageAvatarAssistant"]{{
|
913 |
+
display:none;
|
914 |
+
}}
|
915 |
+
div[data-testid="stChatInput"]{{
|
916 |
+
height:120px !important;
|
917 |
+
}}
|
918 |
+
div[data-testid="stChatInput"]>div{{
|
919 |
+
max-height:200px !important;
|
920 |
+
}}
|
921 |
+
div[class*="st-key-upload"] > div[data-testid="stChatInput"]> div > div:nth-child(4) {{
|
922 |
+
top: 85px;
|
923 |
+
right: 50px;
|
924 |
+
}}
|
925 |
+
|
926 |
+
div[class*="st-key-upload"] > div[data-testid="stChatInput"] > div > div {{
|
927 |
+
margin-top:10px !important;
|
928 |
+
height: 0px;
|
929 |
+
width: -0px;
|
930 |
+
}}
|
931 |
+
div[data-testid ="stSidebarCollapsedControl"]> div > button{{
|
932 |
+
background-image: url(data:image/png;base64,{base64.b64encode(open("close.png", "rb").read()).decode()});
|
933 |
+
background-size: cover; /* size of the image */
|
934 |
+
background-repeat: no-repeat;
|
935 |
+
width:30px !important;
|
936 |
+
margin-left: -15px !important;
|
937 |
+
display: block !important;
|
938 |
+
width: 41px !important;
|
939 |
+
height: 40px;
|
940 |
+
|
941 |
+
}}
|
942 |
+
|
943 |
+
div[data-testid ="stSidebarCollapsedControl"]> div > button > svg{{
|
944 |
+
display:none !important;
|
945 |
+
}}
|
946 |
+
div[data-testid="stSidebarCollapseButton"] > button >svg{{
|
947 |
+
display:none !important;
|
948 |
+
}}
|
949 |
+
div[data-testid="stSidebarCollapseButton"] {{
|
950 |
+
display:block !important;
|
951 |
+
}}
|
952 |
+
div[data-testid ="stSidebarCollapseButton"]> button{{
|
953 |
+
background-image: url(data:image/png;base64,{base64.b64encode(open("close.png", "rb").read()).decode()});
|
954 |
+
background-size: cover; /* size of the image */
|
955 |
+
background-repeat: no-repeat;
|
956 |
+
display:block !important;
|
957 |
+
display: block !important;
|
958 |
+
width: 40px;
|
959 |
+
height: 40px;
|
960 |
+
position:relative;
|
961 |
+
margin-left:-250px !important;
|
962 |
+
margin-top:-20px;
|
963 |
+
|
964 |
+
|
965 |
+
|
966 |
+
|
967 |
+
}}
|
968 |
+
[class*="st-key-content_1"] {{
|
969 |
+
background: white;
|
970 |
+
border-radius: 10px;
|
971 |
+
/* box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);*/
|
972 |
+
width: 90%;
|
973 |
+
margin-left: -100px;
|
974 |
+
/* margin-top: -90px;*/
|
975 |
+
margin-bottom: 20px;
|
976 |
+
margin-right:10px;
|
977 |
+
margin-top:5px !important;
|
978 |
+
padding:100px;
|
979 |
+
overflow-y: auto; /* Enable vertical scrolling for the content */
|
980 |
+
position: fixed; /* Fix the position of the container */
|
981 |
+
top: 1%; /* Adjust top offset */
|
982 |
+
left: 15%; /* Adjust left offset */
|
983 |
+
height: 96.5vh; /* Full viewport height */
|
984 |
+
overflow-x:hidden;
|
985 |
+
overflow-y:hidden;
|
986 |
+
display: flex;
|
987 |
+
|
988 |
+
|
989 |
+
}}
|
990 |
+
|
991 |
+
|
992 |
+
div[data-testid="stSidebarHeader"]{{
|
993 |
+
height:40px !important;
|
994 |
+
position:fixed;
|
995 |
+
z-index:100000000000;
|
996 |
+
background:#f9f9f9;
|
997 |
+
|
998 |
+
width:300px;
|
999 |
+
}}
|
1000 |
+
section[data-testid="stMain"]{{
|
1001 |
+
margin-left:-70px !important;
|
1002 |
+
}}
|
1003 |
+
section[data-testid="stSidebar"]{{
|
1004 |
+
|
1005 |
+
|
1006 |
+
background:#f7f7f8;
|
1007 |
+
|
1008 |
+
}}
|
1009 |
+
[class*="st-key-center-box"] {{
|
1010 |
+
|
1011 |
+
background-color: transparent;
|
1012 |
+
border-radius: 60px;
|
1013 |
+
width: 100%;
|
1014 |
+
margin-top:30px;
|
1015 |
+
top:20% !important; /* Adjust top offset */
|
1016 |
+
left: 1%; /* Adjust left offset */
|
1017 |
+
|
1018 |
+
}}
|
1019 |
+
[class*="st-key-side"] {{
|
1020 |
+
|
1021 |
+
background-color: transparent;
|
1022 |
+
border-radius: 60px;
|
1023 |
+
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.5);
|
1024 |
+
width: 5%;
|
1025 |
+
/* margin-top: 100px;*/
|
1026 |
+
margin-bottom: 10px;
|
1027 |
+
margin-right:10px;
|
1028 |
+
padding:30px;
|
1029 |
+
display: flex;
|
1030 |
+
justify-content: center;
|
1031 |
+
|
1032 |
+
align-items: center;
|
1033 |
+
overflow-y: auto; /* Enable vertical scrolling for the content */
|
1034 |
+
position: fixed; /* Fix the position of the container */
|
1035 |
+
top: 17%; /* Adjust top offset */
|
1036 |
+
left: 16%; /* Adjust left offset */
|
1037 |
+
height:50vh; /* Full viewport height */
|
1038 |
+
|
1039 |
+
}}
|
1040 |
+
|
1041 |
+
[class*="st-key-button_"] .stButton p > img {{
|
1042 |
+
max-width: 100%;
|
1043 |
+
vertical-align: top;
|
1044 |
+
height:130px !important;
|
1045 |
+
object-fit: cover;
|
1046 |
+
padding: 10px;
|
1047 |
+
width:250px !important;
|
1048 |
+
border-radius:10px !important;
|
1049 |
+
max-height: 2em !important;
|
1050 |
+
|
1051 |
+
}}
|
1052 |
+
div.stButton > button {{
|
1053 |
+
color: orange !important; /* White text */
|
1054 |
+
font-family: "Times New Roman " !important; /* Font */
|
1055 |
+
font-size: 18px !important; /* Font size */
|
1056 |
+
font-weight: bold !important; /* Bold text */
|
1057 |
+
padding: 1px 2px; /* Padding for buttons */
|
1058 |
+
border: none; /* Remove border */
|
1059 |
+
border-radius: 5px; /* Rounded corners */
|
1060 |
+
transition: all 0.3s ease-in-out; /* Smooth transition */
|
1061 |
+
display: flex;
|
1062 |
+
align-items: left;
|
1063 |
+
justify-content: left;
|
1064 |
+
margin-left:-15px ;
|
1065 |
+
width:200px;
|
1066 |
+
height:50px;
|
1067 |
+
z-index:1000;
|
1068 |
+
text-align: left; /* Align text to the left */
|
1069 |
+
padding-left: 50px;
|
1070 |
+
|
1071 |
+
}}
|
1072 |
+
div.stButton > button p{{
|
1073 |
+
color: black !important; /* White text */
|
1074 |
+
|
1075 |
+
}}
|
1076 |
+
/* Hover effect */
|
1077 |
+
div.stButton > button:hover {{
|
1078 |
+
box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.4); /* Enhanced shadow on hover */
|
1079 |
+
transform: scale(0.05); /* Slightly enlarge button */
|
1080 |
+
transform: scale(1.01); /* Slight zoom on hover */
|
1081 |
+
box-shadow: 0px 4px 12px rgba(255, 255, 255, 0.4); /* Glow effect */
|
1082 |
+
}}
|
1083 |
+
div.stButton > button:active {{
|
1084 |
+
background: none;
|
1085 |
+
|
1086 |
+
}}
|
1087 |
+
div.stDownloadButton > button:active,
|
1088 |
+
div.stDownloadButton > buttonfocus {{
|
1089 |
+
outline: none; /* Remove the focus outline if you want */
|
1090 |
+
}}
|
1091 |
+
[class*="st-key-button_"] .stButton p > img {{
|
1092 |
+
max-width: 100%;
|
1093 |
+
vertical-align: top;
|
1094 |
+
height:130px !important;
|
1095 |
+
object-fit: cover;
|
1096 |
+
padding: 10px;
|
1097 |
+
width:250px !important;
|
1098 |
+
border-radius:10px !important;
|
1099 |
+
max-height: 2em !important;
|
1100 |
+
|
1101 |
+
}}
|
1102 |
+
div.stDownloadButton > button > div > p {{
|
1103 |
+
font-size:15px !important;
|
1104 |
+
font-weight:bold;
|
1105 |
+
}}
|
1106 |
+
[class*="st-key-button_"] .stButton p{{
|
1107 |
+
font-family: "Times New Roman " !important; /* Font */
|
1108 |
+
font-size:100px !important;
|
1109 |
+
height:150px !important;
|
1110 |
+
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
|
1111 |
+
font-weight: bold;
|
1112 |
+
margin-top:5px;
|
1113 |
+
margin-left:5px;
|
1114 |
+
color:black;
|
1115 |
+
border-radius:10px;
|
1116 |
+
|
1117 |
+
}}
|
1118 |
+
[class*="st-key-button_"]:hover {{
|
1119 |
+
|
1120 |
+
}}
|
1121 |
+
|
1122 |
+
[class*="st-key-nav-"] .stButton p{{
|
1123 |
+
font-family: "Times New Roman " !important; /* Font */
|
1124 |
+
font-size:1rem !important;
|
1125 |
+
font-weight: bold;
|
1126 |
+
|
1127 |
+
}}
|
1128 |
+
[class*="st-key-create"]>div > button
|
1129 |
+
{{
|
1130 |
+
background-image: url(data:image/png;base64,{base64.b64encode(open("side.png", "rb").read()).decode()});
|
1131 |
+
width: 130px !important;
|
1132 |
+
background-size: contain;
|
1133 |
+
background-repeat: no-repeat;
|
1134 |
+
margin-top: -88px !important;
|
1135 |
+
margin-left: -100px !important;
|
1136 |
+
z-index: 100000000000000;
|
1137 |
+
pointer-events: auto; /* Ensure the button is clickable */
|
1138 |
+
border-radius:0px;
|
1139 |
+
|
1140 |
+
|
1141 |
+
}}
|
1142 |
+
|
1143 |
+
|
1144 |
+
.user-image{{
|
1145 |
+
height:100px ;
|
1146 |
+
margin:20px;
|
1147 |
+
}}
|
1148 |
+
|
1149 |
+
/******************************************************/
|
1150 |
+
/* * *choices*************/
|
1151 |
+
|
1152 |
+
|
1153 |
+
|
1154 |
+
|
1155 |
+
[class*="st-key-choices"]{{
|
1156 |
+
margin-left:220px;
|
1157 |
+
padding:30px;
|
1158 |
+
margin-top:{margintop}px !important;
|
1159 |
+
|
1160 |
+
}}
|
1161 |
+
[class*="st-key-choice-1"]{{
|
1162 |
+
background:white !important;
|
1163 |
+
border-radius:15px;
|
1164 |
+
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
|
1165 |
+
width:350px;
|
1166 |
+
|
1167 |
+
|
1168 |
+
}}
|
1169 |
+
[class*="st-key-choice-1"]>div >button{{
|
1170 |
+
|
1171 |
+
background-image: url(data:image/png;base64,{base64.b64encode(open(images, "rb").read()).decode()}) !important;
|
1172 |
+
background-size: 100% 100%;
|
1173 |
+
background-repeat: no-repeat;
|
1174 |
+
background-position:center;
|
1175 |
+
|
1176 |
+
|
1177 |
+
}}
|
1178 |
+
[class*="st-key-choice-1"]>div >button p{{
|
1179 |
+
margin-left:{margin}px !important;
|
1180 |
+
}}
|
1181 |
+
[class*="st-key-choice-2"]>div >button{{
|
1182 |
+
|
1183 |
+
background-image: url(data:image/png;base64,{base64.b64encode(open(image1, "rb").read()).decode()}) !important;
|
1184 |
+
background-repeat: no-repeat;
|
1185 |
+
background-position:center;
|
1186 |
+
background-size: contain;
|
1187 |
+
|
1188 |
+
}}
|
1189 |
+
[class*="st-key-choice-2"]>div >button p{{
|
1190 |
+
margin-left:{margin}px !important;
|
1191 |
+
}}
|
1192 |
+
[class*="st-key-choice-5"]>div >button{{
|
1193 |
+
background-image: url(data:image/png;base64,{base64.b64encode(open(image2, "rb").read()).decode()}) !important;
|
1194 |
+
background-size: contain;
|
1195 |
+
background-position:center;
|
1196 |
+
background-repeat: no-repeat;
|
1197 |
+
|
1198 |
+
}}
|
1199 |
+
[class*="st-key-choice-5"]>div >button p{{
|
1200 |
+
margin-left:{margin}px !important;
|
1201 |
+
}}
|
1202 |
+
[class*="st-key-choice-6"]>div >button{{
|
1203 |
+
|
1204 |
+
background-image: url(data:image/png;base64,{base64.b64encode(open(image3, "rb").read()).decode()}) !important;
|
1205 |
+
background-size: contain;
|
1206 |
+
background-position:center;
|
1207 |
+
|
1208 |
+
background-repeat: no-repeat;
|
1209 |
+
|
1210 |
+
}}
|
1211 |
+
[class*="st-key-choice-6"]>div >button p{{
|
1212 |
+
margin-left:{margin}px !important;
|
1213 |
+
}}
|
1214 |
+
[class*="st-key-choice-"] > div.stButton > button{{
|
1215 |
+
padding-left: 25px !important;
|
1216 |
+
height: 130px !important;
|
1217 |
+
margin-left: 0px !important;
|
1218 |
+
max-width: 400px;
|
1219 |
+
width: 350px;
|
1220 |
+
|
1221 |
+
}}
|
1222 |
+
[class*="st-key-choice-2"]{{
|
1223 |
+
background:white !important;
|
1224 |
+
border-radius:15px;
|
1225 |
+
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
|
1226 |
+
width:350px;
|
1227 |
+
|
1228 |
+
}}
|
1229 |
+
|
1230 |
+
[class*="st-key-choice-5"]{{
|
1231 |
+
background:white !important;
|
1232 |
+
border-radius:15px;
|
1233 |
+
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
|
1234 |
+
width:350px;
|
1235 |
+
|
1236 |
+
|
1237 |
+
}}
|
1238 |
+
[class*="st-key-choice-6"]{{
|
1239 |
+
background:white !important;
|
1240 |
+
border-radius:15px;
|
1241 |
+
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
|
1242 |
+
width:350px;
|
1243 |
+
|
1244 |
+
|
1245 |
+
}}
|
1246 |
+
|
1247 |
+
/*************************************************************/
|
1248 |
+
div[data-testid="stSelectbox"]
|
1249 |
+
{{
|
1250 |
+
width: 297px !important;
|
1251 |
+
background-color: white !important;
|
1252 |
+
margin-top: -118px !important;
|
1253 |
+
position: relative;
|
1254 |
+
margin-left: -8px !important;
|
1255 |
+
z-index:10000000000000000000;
|
1256 |
+
position:fixed;
|
1257 |
+
border-bottom:1px solid #ccc;
|
1258 |
+
border-radius:0px;
|
1259 |
+
height:87px;
|
1260 |
+
padding:15px;
|
1261 |
+
padding-left:100px;
|
1262 |
+
|
1263 |
+
=
|
1264 |
+
|
1265 |
+
}}
|
1266 |
+
div[data-testid="stTextInput"]
|
1267 |
+
{{
|
1268 |
+
background-color: transparent; /* White background */
|
1269 |
+
z-index:100000000;
|
1270 |
+
margin-top: -10px !important;
|
1271 |
+
margin-left: 200px !important;
|
1272 |
+
}}
|
1273 |
+
|
1274 |
+
div[data-testid="stHeading"]
|
1275 |
+
{{
|
1276 |
+
|
1277 |
+
margin-top: 10px !important;
|
1278 |
+
position: relative;
|
1279 |
+
margin-left: 300px !important;
|
1280 |
+
}}
|
1281 |
+
|
1282 |
+
|
1283 |
+
div[data-testid="stTextInput"]>div
|
1284 |
+
{{
|
1285 |
+
width: 900px; /* Full width inside the container */
|
1286 |
+
z-index:10000000000000000;
|
1287 |
+
height:120px;
|
1288 |
+
border-radius:30px;
|
1289 |
+
border:0.5px solid white;
|
1290 |
+
|
1291 |
+
}}
|
1292 |
+
|
1293 |
+
[class*="st-key-btn-new"]>div > button{{
|
1294 |
+
width:40px !important;
|
1295 |
+
margin-top:{top}% !important;
|
1296 |
+
margin-left:{left}% !important;
|
1297 |
+
z-index:10000000;
|
1298 |
+
background-image: url(data:image/png;base64,{base64.b64encode(open("side.png", "rb").read()).decode()});
|
1299 |
+
background-size: contain; /* size of the image */
|
1300 |
+
background-repeat: no-repeat;
|
1301 |
+
position:fixed;
|
1302 |
+
|
1303 |
+
}}
|
1304 |
+
[class*="st-key-input-base"]>div{{
|
1305 |
+
z-index:1000000000000000;
|
1306 |
+
|
1307 |
+
|
1308 |
+
}}
|
1309 |
+
[class*="st-key-base-content"]>div{{
|
1310 |
+
background:transparent !important;
|
1311 |
+
z-index:1000000000000000;
|
1312 |
+
margin-top: 440px !important;
|
1313 |
+
position:fixed;
|
1314 |
+
|
1315 |
+
|
1316 |
+
}}
|
1317 |
+
[class*="st-key-answers"]{{
|
1318 |
+
height:200px !important;
|
1319 |
+
overflow-y:scroll;
|
1320 |
+
overflow-x:hidden;
|
1321 |
+
scroll-behavior: smooth !important;
|
1322 |
+
max-height:300px;
|
1323 |
+
|
1324 |
+
}}
|
1325 |
+
[class*="st-key-uploads"]{{
|
1326 |
+
margin:50px;
|
1327 |
+
margin-top: 10px;
|
1328 |
+
margin-left: 150px;
|
1329 |
+
margin-bottom:80px;
|
1330 |
+
}}
|
1331 |
+
[class*="st-key-imupload"]{{
|
1332 |
+
|
1333 |
+
margin-left: 150px;
|
1334 |
+
}}
|
1335 |
+
|
1336 |
+
[class*="st-key---hist_"]{{
|
1337 |
+
margin-top:-20px !important;
|
1338 |
+
margin-left:-30px;
|
1339 |
+
|
1340 |
+
}}
|
1341 |
+
[class*="st-key---hist_"]>div >button p{{
|
1342 |
+
margin-top:-20px !important;
|
1343 |
+
font-size:16px;
|
1344 |
+
font-family: "Times New Roman" !important; /* Elegant font for title */
|
1345 |
+
color:black !important;
|
1346 |
+
|
1347 |
+
|
1348 |
+
}}
|
1349 |
+
[class*="st-key---hist_"]>div >button {{
|
1350 |
+
padding-left:15px;
|
1351 |
+
width:300px !important;
|
1352 |
+
text-overflow: ellipsis;
|
1353 |
+
|
1354 |
+
}}
|
1355 |
+
[class*="st-key-hist_"]{{
|
1356 |
+
overflow:hidden;
|
1357 |
+
text-overflow: ellipsis;
|
1358 |
+
max-width: 300px;
|
1359 |
+
margin-left:-35px;
|
1360 |
+
}}
|
1361 |
+
h3{{
|
1362 |
+
color:black !important;
|
1363 |
+
font-family: "Times New Roman" !important; /* Elegant font for title */
|
1364 |
+
font-size:18px;
|
1365 |
+
|
1366 |
+
}}
|
1367 |
+
|
1368 |
+
[class*="st-key-nav-"]>div >button{{
|
1369 |
+
width:350px !important;
|
1370 |
+
height:20px !important;
|
1371 |
+
}}
|
1372 |
+
[class*="st-key-nav-"]{{
|
1373 |
+
margin-left:-20px !important;
|
1374 |
+
}}
|
1375 |
+
|
1376 |
+
|
1377 |
+
[class*="st-key-nav-1"]{{
|
1378 |
+
|
1379 |
+
border-radius:80px !important;
|
1380 |
+
border-radius:80px !important;
|
1381 |
+
width:280px !important;
|
1382 |
+
margin-top:50px !important;
|
1383 |
+
background-image: url(data:image/png;base64,{base64.b64encode(open("img.png", "rb").read()).decode()});
|
1384 |
+
background-size: contain; /* size of the image */
|
1385 |
+
background-repeat: no-repeat;
|
1386 |
+
color :black !important;
|
1387 |
+
padding:10px;
|
1388 |
+
padding-left:25px;
|
1389 |
+
|
1390 |
+
}}
|
1391 |
+
|
1392 |
+
[class*="st-key-nav-2"]{{
|
1393 |
+
|
1394 |
+
border-radius:80px !important;
|
1395 |
+
border-radius:80px !important;
|
1396 |
+
width:380px !important;
|
1397 |
+
margin-top:-18px !important;
|
1398 |
+
background-image: url(data:image/png;base64,{base64.b64encode(open("txt.png", "rb").read()).decode()});
|
1399 |
+
background-size: contain; /* size of the image */
|
1400 |
+
background-repeat: no-repeat;
|
1401 |
+
color :black !important;
|
1402 |
+
padding:10px;
|
1403 |
+
padding-left:15px;
|
1404 |
+
height:50px !important;
|
1405 |
+
margin-left:-7px !important;
|
1406 |
+
|
1407 |
+
}}
|
1408 |
+
[class*="st-key-nav-3"]{{
|
1409 |
+
|
1410 |
+
border-radius:80px !important;
|
1411 |
+
border-radius:80px !important;
|
1412 |
+
width:280px !important;
|
1413 |
+
margin-top:-18px !important;
|
1414 |
+
background-image: url(data:image/png;base64,{base64.b64encode(open("gen.png", "rb").read()).decode()});
|
1415 |
+
background-size: contain; /* size of the image */
|
1416 |
+
background-repeat: no-repeat;
|
1417 |
+
color :black !important;
|
1418 |
+
padding:10px;
|
1419 |
+
padding-left:20px;
|
1420 |
+
margin-left:-10px !important;
|
1421 |
+
|
1422 |
+
}}
|
1423 |
+
[class*="st-key-nav-6"] {{
|
1424 |
+
|
1425 |
+
border: none; /* Remove border */
|
1426 |
+
background: transparent !important;
|
1427 |
+
border-radius:80px !important;
|
1428 |
+
backdrop-filter: blur(10px) !important;
|
1429 |
+
border-radius:80px !important;
|
1430 |
+
width:190px !important;
|
1431 |
+
margin-top:35px !important;
|
1432 |
+
|
1433 |
+
}}
|
1434 |
+
|
1435 |
+
|
1436 |
+
</style>
|
1437 |
+
""",
|
1438 |
+
unsafe_allow_html=True
|
1439 |
+
)
|
1440 |
+
loading_html = """
|
1441 |
+
<style>
|
1442 |
+
.loader {
|
1443 |
+
border: 8px solid #f3f3f3;
|
1444 |
+
border-top: 8px solid #0175C2; /* Blue color */
|
1445 |
+
border-radius: 50%;
|
1446 |
+
width: 50px;
|
1447 |
+
height: 50px;
|
1448 |
+
animation: spin 1s linear infinite;
|
1449 |
+
margin: auto;
|
1450 |
+
}
|
1451 |
+
@keyframes spin {
|
1452 |
+
0% { transform: rotate(0deg); }
|
1453 |
+
100% { transform: rotate(360deg); }
|
1454 |
+
}
|
1455 |
+
|
1456 |
+
</style>
|
1457 |
+
<div class="loader"></div>
|
1458 |
+
"""
|
1459 |
+
# Sort chat files by last modified time (most recent first)
|
1460 |
+
chat_files = sorted(
|
1461 |
+
os.listdir(CHAT_DIR),
|
1462 |
+
key=lambda x: os.path.getmtime(os.path.join(CHAT_DIR, x)),
|
1463 |
+
reverse=True
|
1464 |
+
)
|
1465 |
+
|
1466 |
+
# Sidebar buttons
|
1467 |
+
with st.sidebar:
|
1468 |
+
if st.button(" Text Classification",key="nav-1"):
|
1469 |
+
st.session_state.menu ="class" # Store state
|
1470 |
+
st.rerun()
|
1471 |
+
if st.button(" Text Generation",key="nav-2"):
|
1472 |
+
st.session_state.menu ="gen" # Store state
|
1473 |
+
st.rerun()
|
1474 |
+
if st.button(" Image to text Generator",key="nav-3"):
|
1475 |
+
st.session_state.menu ="image" # Store state
|
1476 |
+
st.rerun()
|
1477 |
+
st.markdown("### 💬 Previous Chats")
|
1478 |
+
|
1479 |
+
# List existing chats as buttons
|
1480 |
+
# List existing chats as buttons with a delete icon
|
1481 |
+
for chat_file in chat_files:
|
1482 |
+
chat_id = chat_file.replace(".json", "")
|
1483 |
+
file_path = os.path.join(CHAT_DIR, chat_file)
|
1484 |
+
|
1485 |
+
try:
|
1486 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
1487 |
+
data = json.load(f)
|
1488 |
+
|
1489 |
+
if data:
|
1490 |
+
# Get first user message
|
1491 |
+
first_user_message = next(
|
1492 |
+
(msg["content"] for msg in data if msg["role"] == "user"), "🆕 New Chat"
|
1493 |
+
)
|
1494 |
+
preview_line = first_user_message.strip().split("\n")[0]
|
1495 |
+
truncated_preview = preview_line[:50] + ("..." if len(preview_line) > 50 else "")
|
1496 |
+
|
1497 |
+
# Generate keys
|
1498 |
+
val = f"hist_{chat_id}"
|
1499 |
+
delete_key = f"del_{chat_id}"
|
1500 |
+
|
1501 |
+
# Create side-by-side buttons
|
1502 |
+
col1, col2 = st.columns([4, 1])
|
1503 |
+
key = f"col_{chat_id}"
|
1504 |
+
with st.container(key=key):
|
1505 |
+
with col1:
|
1506 |
+
if st.button(f"🗂 {truncated_preview}", key=val):
|
1507 |
+
load_chat_history(chat_id)
|
1508 |
+
|
1509 |
+
with col2:
|
1510 |
+
if st.button("🗑️", key=delete_key):
|
1511 |
+
os.remove(file_path)
|
1512 |
+
st.success(f"Deleted chat: {chat_id}")
|
1513 |
+
st.rerun()
|
1514 |
+
|
1515 |
+
except (json.JSONDecodeError, FileNotFoundError):
|
1516 |
+
pass # Skip invalid files
|
1517 |
+
|
1518 |
+
# Add your model description logic here
|
1519 |
+
if st.button("",key ="btn-new"):
|
1520 |
+
st.session_state.show_overlay = True
|
1521 |
+
# Set new ID based on existing files
|
1522 |
+
new_id = f"chat_{len(os.listdir(CHAT_DIR)) + 1}"
|
1523 |
+
st.session_state.chat_id = new_id
|
1524 |
+
st.session_state.messages = []
|
1525 |
+
save_chat_history() # Save empty history to create the file
|
1526 |
+
st.rerun()
|
1527 |
+
with st.container(key="content_1"):
|
1528 |
+
if st.button("",key ="create"):
|
1529 |
+
st.session_state.show_overlay = True
|
1530 |
+
st.rerun()
|
1531 |
+
model_names = [m["model"] for m in st.session_state.models]
|
1532 |
+
selected_model_name = st.selectbox(task, model_names)
|
1533 |
+
selected_model = next((m for m in st.session_state.models if m["model"] == selected_model_name), None)
|
1534 |
+
if st.session_state.show_overlay == True:
|
1535 |
+
st.header(f"{text_h1} – What can I help you with?")
|
1536 |
+
user_input = ''
|
1537 |
+
if st.session_state.menu != "image":
|
1538 |
+
if user_input := st.chat_input("Ask anything",key="imupload"):
|
1539 |
+
st.session_state.user_input = user_input
|
1540 |
+
st.session_state.show_overlay = False
|
1541 |
+
# Add user message
|
1542 |
+
# Add user message to history
|
1543 |
+
st.session_state.messages.append({
|
1544 |
+
"role": "user",
|
1545 |
+
"content": user_input,
|
1546 |
+
"image": st.session_state.save_path if st.session_state.menu == "image" else ""
|
1547 |
+
})
|
1548 |
+
# Simulate assistant response (replace with real AI later)
|
1549 |
+
|
1550 |
+
# Indicate that a response should be generated on the chat page
|
1551 |
+
st.session_state.input_text = st.session_state.user_input
|
1552 |
+
st.session_state.input_task = "text"
|
1553 |
+
|
1554 |
+
|
1555 |
+
st.session_state.generate_response = True
|
1556 |
+
st.rerun()
|
1557 |
+
|
1558 |
+
if st.session_state.menu == "image":
|
1559 |
+
if prompts := st.chat_input(
|
1560 |
+
"Say something and/or attach an image",
|
1561 |
+
accept_file=True,
|
1562 |
+
file_type=["jpg", "jpeg", "png"],key = "uploads"
|
1563 |
+
): # Step 3: Open the image using PIL
|
1564 |
+
files = prompts["files"]
|
1565 |
+
text_input = prompts["text"]
|
1566 |
+
|
1567 |
+
# Optional image handling
|
1568 |
+
image_path = ""
|
1569 |
+
if files:
|
1570 |
+
file = files[0]
|
1571 |
+
image = Image.open(file)
|
1572 |
+
save_dir = "saved_images"
|
1573 |
+
os.makedirs(save_dir, exist_ok=True)
|
1574 |
+
save_path = os.path.join(save_dir, file.name)
|
1575 |
+
image.save(save_path)
|
1576 |
+
st.session_state.save_path = save_path
|
1577 |
+
image_path = save_path # So you can add it to messages
|
1578 |
+
|
1579 |
+
#st.session_state.show_overlay = False
|
1580 |
+
|
1581 |
+
st.session_state.show_overlay = False
|
1582 |
+
# Add user message
|
1583 |
+
st.session_state.messages.append({
|
1584 |
+
"role": "user",
|
1585 |
+
"content": image_path,
|
1586 |
+
"image": st.session_state.save_path
|
1587 |
+
})
|
1588 |
+
st.session_state.input_text = st.session_state.save_path
|
1589 |
+
st.session_state.input_task = "image"
|
1590 |
+
|
1591 |
+
# assistant response
|
1592 |
+
|
1593 |
+
# Indicate that a response should be generated on the chat page
|
1594 |
+
st.session_state.generate_response = True
|
1595 |
+
|
1596 |
+
st.rerun()
|
1597 |
+
|
1598 |
+
with st.container(key="choices"):
|
1599 |
+
col1,col2,col3,col4 = st.columns([1.5,0.1,1.5,1])
|
1600 |
+
with col1:
|
1601 |
+
if st.button(choice1,key="choice-1"):
|
1602 |
+
st.session_state.user_input = choice1
|
1603 |
+
if st.session_state.menu == "image":
|
1604 |
+
st.session_state.messages.append({
|
1605 |
+
"role": "user",
|
1606 |
+
"content": images,
|
1607 |
+
"image": images
|
1608 |
+
})
|
1609 |
+
st.session_state.input_task = "image"
|
1610 |
+
st.session_state.input_text = images
|
1611 |
+
|
1612 |
+
# assistant response
|
1613 |
+
|
1614 |
+
# Indicate that a response should be generated on the chat page
|
1615 |
+
else:
|
1616 |
+
st.session_state.input_text = choice1
|
1617 |
+
st.session_state.input_task = "text"
|
1618 |
+
|
1619 |
+
st.session_state.messages.append({
|
1620 |
+
"role": "user",
|
1621 |
+
"content": choice1,
|
1622 |
+
"image":""
|
1623 |
+
|
1624 |
+
})
|
1625 |
+
|
1626 |
+
st.session_state.show_overlay = False
|
1627 |
+
st.session_state.generate_response = True
|
1628 |
+
st.rerun()
|
1629 |
+
if st.button(choice2,key="choice-2"):
|
1630 |
+
st.session_state.user_input = choice2
|
1631 |
+
if st.session_state.menu == "image":
|
1632 |
+
st.session_state.input_task = "image"
|
1633 |
+
st.session_state.input_text = image1
|
1634 |
+
st.session_state.messages.append({
|
1635 |
+
"role": "user",
|
1636 |
+
"content": image1,
|
1637 |
+
"image": image1
|
1638 |
+
})
|
1639 |
+
else:
|
1640 |
+
st.session_state.input_text = choice2
|
1641 |
+
st.session_state.input_task = "text"
|
1642 |
+
|
1643 |
+
st.session_state.messages.append({
|
1644 |
+
"role": "user",
|
1645 |
+
"content": choice2,
|
1646 |
+
"image":""
|
1647 |
+
|
1648 |
+
})
|
1649 |
+
st.session_state.generate_response = True
|
1650 |
+
st.session_state.show_overlay = False
|
1651 |
+
st.rerun()
|
1652 |
+
with col3:
|
1653 |
+
if st.button(choice3,key="choice-5"):
|
1654 |
+
st.session_state.user_input = choice3
|
1655 |
+
if st.session_state.menu == "image":
|
1656 |
+
st.session_state.input_task = "image"
|
1657 |
+
st.session_state.input_text = image2
|
1658 |
+
st.session_state.messages.append({
|
1659 |
+
"role": "user",
|
1660 |
+
"content": image2,
|
1661 |
+
"image": image2
|
1662 |
+
})
|
1663 |
+
else:
|
1664 |
+
st.session_state.input_text = choice3
|
1665 |
+
st.session_state.input_task = "text"
|
1666 |
+
st.session_state.messages.append({
|
1667 |
+
"role": "user",
|
1668 |
+
"content": choice3,
|
1669 |
+
"image":""
|
1670 |
+
|
1671 |
+
})
|
1672 |
+
st.session_state.generate_response = True
|
1673 |
+
st.session_state.show_overlay = False
|
1674 |
+
st.rerun()
|
1675 |
+
|
1676 |
+
if st.button(choice4,key="choice-6"):
|
1677 |
+
st.session_state.user_input = choice4
|
1678 |
+
if st.session_state.menu == "image":
|
1679 |
+
st.session_state.input_task = "image"
|
1680 |
+
st.session_state.input_text = image3
|
1681 |
+
st.session_state.messages.append({
|
1682 |
+
"role": "user",
|
1683 |
+
"content": image3,
|
1684 |
+
"image": image3
|
1685 |
+
})
|
1686 |
+
else:
|
1687 |
+
st.session_state.input_text = choice4
|
1688 |
+
st.session_state.input_task = "text"
|
1689 |
+
st.session_state.messages.append({
|
1690 |
+
"role": "user",
|
1691 |
+
"content": choice4,
|
1692 |
+
"image":""
|
1693 |
+
})
|
1694 |
+
st.session_state.generate_response = True
|
1695 |
+
|
1696 |
+
st.session_state.show_overlay = False
|
1697 |
+
st.rerun()
|
1698 |
+
|
1699 |
+
if st.session_state.show_overlay == False:
|
1700 |
+
def generate_stream_response(text):
|
1701 |
+
# Yield the string one character at a time (for streaming)
|
1702 |
+
for char in text:
|
1703 |
+
yield char
|
1704 |
+
time.sleep(0.02)
|
1705 |
+
|
1706 |
+
|
1707 |
+
|
1708 |
+
# Display chat messages from history on app rerun
|
1709 |
+
if st.session_state.get("generate_response", True):
|
1710 |
+
with st.spinner("generating output..."):
|
1711 |
+
response = query_huggingface_model(
|
1712 |
+
selected_model,
|
1713 |
+
st.session_state.input_text,
|
1714 |
+
input_type=st.session_state.input_task,
|
1715 |
+
task=task
|
1716 |
+
)
|
1717 |
+
|
1718 |
+
st.session_state.messages.append({
|
1719 |
+
"role": "assistant",
|
1720 |
+
"content": extract_response_content(response),
|
1721 |
+
"image": "",
|
1722 |
+
"model": selected_model['model']
|
1723 |
+
})
|
1724 |
+
|
1725 |
+
st.session_state.generate_response = False # Reset the flag
|
1726 |
+
save_chat_history()
|
1727 |
+
st.rerun()
|
1728 |
+
|
1729 |
+
for i, message in enumerate(st.session_state.messages):
|
1730 |
+
con = message["role"]
|
1731 |
+
container_key = f"{con}-{i}"
|
1732 |
+
with st.container(key=container_key):
|
1733 |
+
with st.chat_message(message["role"]):
|
1734 |
+
if message["role"] == "assistant":
|
1735 |
+
st.markdown(f"**Model:** `{message['model']}`")
|
1736 |
+
if message["image"] != "":
|
1737 |
+
st.markdown(f"""<img src="data:image/png;base64,{base64.b64encode(open(message["image"],"rb").read()).decode()}" class="user-image" alt="Uploaded Image"> """,unsafe_allow_html=True,)
|
1738 |
+
st.markdown(message["content"])
|
1739 |
+
if st.session_state.menu == "image":
|
1740 |
+
if prompts := st.chat_input(
|
1741 |
+
"Say something and/or attach an image",
|
1742 |
+
accept_file=True,
|
1743 |
+
file_type=["jpg", "jpeg", "png"],key = "upload"
|
1744 |
+
):
|
1745 |
+
files = prompts["files"]
|
1746 |
+
text_input = prompts["text"]
|
1747 |
+
|
1748 |
+
# Optional image handling
|
1749 |
+
image_path = ""
|
1750 |
+
if files:
|
1751 |
+
file = files[0]
|
1752 |
+
image = Image.open(file)
|
1753 |
+
save_dir = "saved_images"
|
1754 |
+
os.makedirs(save_dir, exist_ok=True)
|
1755 |
+
save_path = os.path.join(save_dir, file.name)
|
1756 |
+
image.save(save_path)
|
1757 |
+
st.session_state.save_path = save_path
|
1758 |
+
image_path = save_path # So you can add it to messages
|
1759 |
+
|
1760 |
+
|
1761 |
+
# Show in chat window
|
1762 |
+
with st.container(key="user-k"):
|
1763 |
+
with st.chat_message("user"):
|
1764 |
+
st.markdown(text_input)
|
1765 |
+
if image_path:
|
1766 |
+
st.markdown(f"""<img src="data:image/png;base64,{base64.b64encode(open(image_path,"rb").read()).decode()}" class="user-image" alt="Uploaded Image"> """,unsafe_allow_html=True,)
|
1767 |
+
|
1768 |
+
with st.container(key="assistant-k"):
|
1769 |
+
# Display assistant response in chat message container
|
1770 |
+
with st.chat_message("assistant"):
|
1771 |
+
|
1772 |
+
with st.spinner("Model is generating a response..."):
|
1773 |
+
# Add message to history
|
1774 |
+
result = query_huggingface_model(selected_model, st.session_state.save_path , input_type="image")
|
1775 |
+
st.session_state.messages.append({
|
1776 |
+
"role": "user",
|
1777 |
+
"content": text_input,
|
1778 |
+
"image": image_path
|
1779 |
+
})
|
1780 |
+
response = extract_response_content(result)
|
1781 |
+
st.markdown(f"**Model:** `{selected_model['model'] if isinstance(selected_model, dict) else selected_model}`")
|
1782 |
+
print(response)
|
1783 |
+
st.write_stream(generate_stream_response(response)) # This will stream the text one character at a time
|
1784 |
+
# Add assistant response to chat history
|
1785 |
+
st.session_state.messages.append({"role": "assistant", "content": response,"image":"","model":selected_model['model']})
|
1786 |
+
save_chat_history()
|
1787 |
+
|
1788 |
+
else:
|
1789 |
+
# Accept user input
|
1790 |
+
if prompt := st.chat_input("Ask anything"):
|
1791 |
+
|
1792 |
+
# Display user message in chat message container
|
1793 |
+
with st.container(key="user-k"):
|
1794 |
+
|
1795 |
+
with st.chat_message("user"):
|
1796 |
+
st.markdown(prompt)
|
1797 |
+
# Add user message to chat history
|
1798 |
+
|
1799 |
+
|
1800 |
+
with st.container(key="assistant-k"):
|
1801 |
+
|
1802 |
+
# Display assistant response in chat message container
|
1803 |
+
with st.chat_message("assistant"):
|
1804 |
+
with st.spinner("Model is generating a response..."):
|
1805 |
+
st.session_state.messages.append({"role": "user", "content": prompt,"image":""})
|
1806 |
+
result = query_huggingface_model(selected_model, prompt , input_type="text",task=task)
|
1807 |
+
st.markdown(f"**Model:** `{selected_model['model'] if isinstance(selected_model, dict) else selected_model}`")
|
1808 |
+
response = extract_response_content(result)
|
1809 |
+
st.write_stream(generate_stream_response(response)) # Add assistant response to chat history
|
1810 |
+
st.session_state.messages.append({"role": "assistant", "content": response,"image":"","model":selected_model['model']})
|
1811 |
+
save_chat_history()
|