Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ from streamlit_lottie import st_lottie
|
|
| 11 |
from streamlit_option_menu import option_menu
|
| 12 |
import time
|
| 13 |
|
| 14 |
-
# Set page
|
| 15 |
st.set_page_config(
|
| 16 |
page_title="TeleGuide | AI Telecom Assistant",
|
| 17 |
page_icon="🛰️",
|
|
@@ -19,7 +19,7 @@ st.set_page_config(
|
|
| 19 |
initial_sidebar_state="expanded"
|
| 20 |
)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
def load_lottie(url: str):
|
| 24 |
try:
|
| 25 |
r = requests.get(url)
|
|
@@ -29,23 +29,18 @@ def load_lottie(url: str):
|
|
| 29 |
except:
|
| 30 |
return None
|
| 31 |
|
| 32 |
-
#
|
| 33 |
st.markdown("""
|
| 34 |
<style>
|
| 35 |
-
/* Main app styling */
|
| 36 |
.stApp {
|
| 37 |
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
| 38 |
}
|
| 39 |
-
|
| 40 |
-
/* Card-like containers */
|
| 41 |
.css-1r6slb0 {
|
| 42 |
background: white;
|
| 43 |
border-radius: 20px;
|
| 44 |
padding: 20px;
|
| 45 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 46 |
}
|
| 47 |
-
|
| 48 |
-
/* Header styling */
|
| 49 |
.main-header {
|
| 50 |
font-size: 2.5rem;
|
| 51 |
font-weight: 700;
|
|
@@ -54,8 +49,6 @@ st.markdown("""
|
|
| 54 |
margin-bottom: 2rem;
|
| 55 |
animation: fadeIn 1.5s ease-in;
|
| 56 |
}
|
| 57 |
-
|
| 58 |
-
/* Button styling */
|
| 59 |
.stButton>button {
|
| 60 |
width: 100%;
|
| 61 |
border-radius: 10px;
|
|
@@ -65,13 +58,10 @@ st.markdown("""
|
|
| 65 |
padding: 0.5rem 1rem;
|
| 66 |
transition: all 0.3s ease;
|
| 67 |
}
|
| 68 |
-
|
| 69 |
.stButton>button:hover {
|
| 70 |
transform: translateY(-2px);
|
| 71 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
| 72 |
}
|
| 73 |
-
|
| 74 |
-
/* Input field styling */
|
| 75 |
.stTextInput>div>div>input,
|
| 76 |
.stTextArea>div>div>textarea {
|
| 77 |
border-radius: 10px;
|
|
@@ -79,23 +69,16 @@ st.markdown("""
|
|
| 79 |
padding: 10px;
|
| 80 |
background-color: white;
|
| 81 |
}
|
| 82 |
-
|
| 83 |
-
/* Sidebar styling */
|
| 84 |
.css-1d391kg {
|
| 85 |
background: linear-gradient(180deg, #1E3D59 0%, #2193b0 100%);
|
| 86 |
}
|
| 87 |
-
|
| 88 |
-
/* Animations */
|
| 89 |
@keyframes fadeIn {
|
| 90 |
from { opacity: 0; transform: translateY(20px); }
|
| 91 |
to { opacity: 1; transform: translateY(0); }
|
| 92 |
}
|
| 93 |
-
|
| 94 |
.fade-in {
|
| 95 |
animation: fadeIn 1s ease-in;
|
| 96 |
}
|
| 97 |
-
|
| 98 |
-
/* Status messages */
|
| 99 |
.success-message {
|
| 100 |
padding: 1rem;
|
| 101 |
border-radius: 10px;
|
|
@@ -103,7 +86,6 @@ st.markdown("""
|
|
| 103 |
color: #155724;
|
| 104 |
margin: 1rem 0;
|
| 105 |
}
|
| 106 |
-
|
| 107 |
.error-message {
|
| 108 |
padding: 1rem;
|
| 109 |
border-radius: 10px;
|
|
@@ -114,11 +96,13 @@ st.markdown("""
|
|
| 114 |
</style>
|
| 115 |
""", unsafe_allow_html=True)
|
| 116 |
|
| 117 |
-
# Initialize
|
| 118 |
@st.cache_resource
|
| 119 |
def get_openai_client():
|
| 120 |
try:
|
| 121 |
-
|
|
|
|
|
|
|
| 122 |
except Exception as e:
|
| 123 |
st.error(f"Error initializing API client: {str(e)}")
|
| 124 |
return None
|
|
@@ -129,6 +113,7 @@ client = get_openai_client()
|
|
| 129 |
lottie_telecom = load_lottie("https://assets4.lottiefiles.com/packages/lf20_qz3tpn4w.json")
|
| 130 |
lottie_analysis = load_lottie("https://assets4.lottiefiles.com/packages/lf20_xh83pj1k.json")
|
| 131 |
|
|
|
|
| 132 |
def process_text_query(query, model="meta-llama/Llama-3.2-3B-Instruct-Turbo"):
|
| 133 |
try:
|
| 134 |
with st.spinner("Processing your query..."):
|
|
@@ -146,6 +131,7 @@ def process_text_query(query, model="meta-llama/Llama-3.2-3B-Instruct-Turbo"):
|
|
| 146 |
st.error(f"Error processing query: {str(e)}")
|
| 147 |
return None
|
| 148 |
|
|
|
|
| 149 |
def process_image_query(image_base64, query, model="meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo"):
|
| 150 |
try:
|
| 151 |
with st.spinner("Analyzing image..."):
|
|
@@ -170,6 +156,7 @@ def process_image_query(image_base64, query, model="meta-llama/Llama-3.2-90B-Vis
|
|
| 170 |
st.error(f"Error analyzing image: {str(e)}")
|
| 171 |
return None
|
| 172 |
|
|
|
|
| 173 |
def image_to_base64(image):
|
| 174 |
try:
|
| 175 |
buffered = io.BytesIO()
|
|
@@ -179,7 +166,7 @@ def image_to_base64(image):
|
|
| 179 |
st.error(f"Error converting image: {str(e)}")
|
| 180 |
return None
|
| 181 |
|
| 182 |
-
# Sidebar
|
| 183 |
with st.sidebar:
|
| 184 |
st.title("🛰️ TeleGuide")
|
| 185 |
st_lottie(lottie_telecom, height=200)
|
|
@@ -199,7 +186,7 @@ with st.sidebar:
|
|
| 199 |
# Main content
|
| 200 |
st.markdown('<h1 class="main-header">Welcome to TeleGuide</h1>', unsafe_allow_html=True)
|
| 201 |
|
| 202 |
-
# Navigation
|
| 203 |
selected = option_menu(
|
| 204 |
menu_title=None,
|
| 205 |
options=["Text Analysis", "Document Processing", "Image Analysis"],
|
|
@@ -220,6 +207,7 @@ selected = option_menu(
|
|
| 220 |
}
|
| 221 |
)
|
| 222 |
|
|
|
|
| 223 |
if selected == "Text Analysis":
|
| 224 |
st.markdown("### 💬 Text Analysis")
|
| 225 |
st_lottie(lottie_analysis, height=200)
|
|
@@ -245,51 +233,36 @@ elif selected == "Document Processing":
|
|
| 245 |
text_input = st.text_area("Enter document text:", height=150)
|
| 246 |
if st.button("Analyze Document"):
|
| 247 |
if text_input:
|
| 248 |
-
|
| 249 |
-
response = process_text_query(analysis_prompt)
|
| 250 |
if response:
|
| 251 |
st.markdown('<div class="success-message">✅ Document analyzed successfully!</div>', unsafe_allow_html=True)
|
| 252 |
-
st.markdown("###
|
| 253 |
st.write(response)
|
| 254 |
else:
|
| 255 |
-
st.warning("Please enter
|
| 256 |
|
| 257 |
elif selected == "Image Analysis":
|
| 258 |
st.markdown("### 🖼️ Image Analysis")
|
| 259 |
-
|
| 260 |
-
"Select Image Type",
|
| 261 |
-
["Network Infrastructure", "Equipment", "Site Survey", "Signal Coverage"]
|
| 262 |
-
)
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
else:
|
| 281 |
-
st.warning("Please enter analysis requirements.")
|
| 282 |
-
except Exception as e:
|
| 283 |
-
st.error(f"Error processing image: {str(e)}")
|
| 284 |
|
| 285 |
# Footer
|
| 286 |
st.markdown("---")
|
| 287 |
-
st.
|
| 288 |
-
|
| 289 |
-
<div style='text-align: center; color: #666;'>
|
| 290 |
-
<p>TeleGuide - Your AI-Powered Telecommunications Assistant</p>
|
| 291 |
-
<p>Made with ❤️ for telecom professionals</p>
|
| 292 |
-
</div>
|
| 293 |
-
""",
|
| 294 |
-
unsafe_allow_html=True
|
| 295 |
-
)
|
|
|
|
| 11 |
from streamlit_option_menu import option_menu
|
| 12 |
import time
|
| 13 |
|
| 14 |
+
# Set page configuration
|
| 15 |
st.set_page_config(
|
| 16 |
page_title="TeleGuide | AI Telecom Assistant",
|
| 17 |
page_icon="🛰️",
|
|
|
|
| 19 |
initial_sidebar_state="expanded"
|
| 20 |
)
|
| 21 |
|
| 22 |
+
# Function to load Lottie animations
|
| 23 |
def load_lottie(url: str):
|
| 24 |
try:
|
| 25 |
r = requests.get(url)
|
|
|
|
| 29 |
except:
|
| 30 |
return None
|
| 31 |
|
| 32 |
+
# Apply custom CSS for styling and animations
|
| 33 |
st.markdown("""
|
| 34 |
<style>
|
|
|
|
| 35 |
.stApp {
|
| 36 |
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
| 37 |
}
|
|
|
|
|
|
|
| 38 |
.css-1r6slb0 {
|
| 39 |
background: white;
|
| 40 |
border-radius: 20px;
|
| 41 |
padding: 20px;
|
| 42 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 43 |
}
|
|
|
|
|
|
|
| 44 |
.main-header {
|
| 45 |
font-size: 2.5rem;
|
| 46 |
font-weight: 700;
|
|
|
|
| 49 |
margin-bottom: 2rem;
|
| 50 |
animation: fadeIn 1.5s ease-in;
|
| 51 |
}
|
|
|
|
|
|
|
| 52 |
.stButton>button {
|
| 53 |
width: 100%;
|
| 54 |
border-radius: 10px;
|
|
|
|
| 58 |
padding: 0.5rem 1rem;
|
| 59 |
transition: all 0.3s ease;
|
| 60 |
}
|
|
|
|
| 61 |
.stButton>button:hover {
|
| 62 |
transform: translateY(-2px);
|
| 63 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
| 64 |
}
|
|
|
|
|
|
|
| 65 |
.stTextInput>div>div>input,
|
| 66 |
.stTextArea>div>div>textarea {
|
| 67 |
border-radius: 10px;
|
|
|
|
| 69 |
padding: 10px;
|
| 70 |
background-color: white;
|
| 71 |
}
|
|
|
|
|
|
|
| 72 |
.css-1d391kg {
|
| 73 |
background: linear-gradient(180deg, #1E3D59 0%, #2193b0 100%);
|
| 74 |
}
|
|
|
|
|
|
|
| 75 |
@keyframes fadeIn {
|
| 76 |
from { opacity: 0; transform: translateY(20px); }
|
| 77 |
to { opacity: 1; transform: translateY(0); }
|
| 78 |
}
|
|
|
|
| 79 |
.fade-in {
|
| 80 |
animation: fadeIn 1s ease-in;
|
| 81 |
}
|
|
|
|
|
|
|
| 82 |
.success-message {
|
| 83 |
padding: 1rem;
|
| 84 |
border-radius: 10px;
|
|
|
|
| 86 |
color: #155724;
|
| 87 |
margin: 1rem 0;
|
| 88 |
}
|
|
|
|
| 89 |
.error-message {
|
| 90 |
padding: 1rem;
|
| 91 |
border-radius: 10px;
|
|
|
|
| 96 |
</style>
|
| 97 |
""", unsafe_allow_html=True)
|
| 98 |
|
| 99 |
+
# Initialize OpenAI client with Hugging Face secrets for API key
|
| 100 |
@st.cache_resource
|
| 101 |
def get_openai_client():
|
| 102 |
try:
|
| 103 |
+
# Fetch the API key from Hugging Face secrets
|
| 104 |
+
api_key = st.secrets["api_key"]
|
| 105 |
+
return OpenAI(api_key=api_key, base_url="https://api.together.xyz")
|
| 106 |
except Exception as e:
|
| 107 |
st.error(f"Error initializing API client: {str(e)}")
|
| 108 |
return None
|
|
|
|
| 113 |
lottie_telecom = load_lottie("https://assets4.lottiefiles.com/packages/lf20_qz3tpn4w.json")
|
| 114 |
lottie_analysis = load_lottie("https://assets4.lottiefiles.com/packages/lf20_xh83pj1k.json")
|
| 115 |
|
| 116 |
+
# Process text query function
|
| 117 |
def process_text_query(query, model="meta-llama/Llama-3.2-3B-Instruct-Turbo"):
|
| 118 |
try:
|
| 119 |
with st.spinner("Processing your query..."):
|
|
|
|
| 131 |
st.error(f"Error processing query: {str(e)}")
|
| 132 |
return None
|
| 133 |
|
| 134 |
+
# Process image query function
|
| 135 |
def process_image_query(image_base64, query, model="meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo"):
|
| 136 |
try:
|
| 137 |
with st.spinner("Analyzing image..."):
|
|
|
|
| 156 |
st.error(f"Error analyzing image: {str(e)}")
|
| 157 |
return None
|
| 158 |
|
| 159 |
+
# Convert image to base64
|
| 160 |
def image_to_base64(image):
|
| 161 |
try:
|
| 162 |
buffered = io.BytesIO()
|
|
|
|
| 166 |
st.error(f"Error converting image: {str(e)}")
|
| 167 |
return None
|
| 168 |
|
| 169 |
+
# Sidebar content
|
| 170 |
with st.sidebar:
|
| 171 |
st.title("🛰️ TeleGuide")
|
| 172 |
st_lottie(lottie_telecom, height=200)
|
|
|
|
| 186 |
# Main content
|
| 187 |
st.markdown('<h1 class="main-header">Welcome to TeleGuide</h1>', unsafe_allow_html=True)
|
| 188 |
|
| 189 |
+
# Navigation menu
|
| 190 |
selected = option_menu(
|
| 191 |
menu_title=None,
|
| 192 |
options=["Text Analysis", "Document Processing", "Image Analysis"],
|
|
|
|
| 207 |
}
|
| 208 |
)
|
| 209 |
|
| 210 |
+
# Handle different options from the navigation menu
|
| 211 |
if selected == "Text Analysis":
|
| 212 |
st.markdown("### 💬 Text Analysis")
|
| 213 |
st_lottie(lottie_analysis, height=200)
|
|
|
|
| 233 |
text_input = st.text_area("Enter document text:", height=150)
|
| 234 |
if st.button("Analyze Document"):
|
| 235 |
if text_input:
|
| 236 |
+
response = process_text_query(f"Analyze the following {document_type}: {text_input}")
|
|
|
|
| 237 |
if response:
|
| 238 |
st.markdown('<div class="success-message">✅ Document analyzed successfully!</div>', unsafe_allow_html=True)
|
| 239 |
+
st.markdown("### Response:")
|
| 240 |
st.write(response)
|
| 241 |
else:
|
| 242 |
+
st.warning("Please enter some text to analyze.")
|
| 243 |
|
| 244 |
elif selected == "Image Analysis":
|
| 245 |
st.markdown("### 🖼️ Image Analysis")
|
| 246 |
+
image_file = st.file_uploader("Upload an image for analysis", type=["jpg", "jpeg", "png"])
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
+
if image_file:
|
| 249 |
+
image = Image.open(image_file)
|
| 250 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 251 |
+
|
| 252 |
+
query = st.text_input("Enter your query about this image:")
|
| 253 |
+
|
| 254 |
+
if st.button("Analyze Image"):
|
| 255 |
+
image_base64 = image_to_base64(image)
|
| 256 |
+
if image_base64 and query:
|
| 257 |
+
response = process_image_query(image_base64, query)
|
| 258 |
+
if response:
|
| 259 |
+
st.markdown('<div class="success-message">✅ Image analyzed successfully!</div>', unsafe_allow_html=True)
|
| 260 |
+
st.markdown("### Response:")
|
| 261 |
+
st.write(response)
|
| 262 |
+
else:
|
| 263 |
+
st.warning("Please upload an image and enter a query.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
# Footer
|
| 266 |
st.markdown("---")
|
| 267 |
+
st.caption("🚀 Powered by OpenAI | Streamlit | Llama Models")
|
| 268 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|