Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,8 @@ import uuid
|
|
| 16 |
from langchain_community.chat_message_histories import ChatMessageHistory
|
| 17 |
from langchain_core.runnables.history import RunnableWithMessageHistory
|
| 18 |
import gradio as gr
|
|
|
|
|
|
|
| 19 |
|
| 20 |
load_dotenv(dotenv_path='api.env.txt')
|
| 21 |
Langchain_API_KEY = os.getenv('LANGCHAIN_API')
|
|
@@ -210,23 +212,49 @@ agent_with_chat_history = RunnableWithMessageHistory(
|
|
| 210 |
session_ids = {}
|
| 211 |
|
| 212 |
def gradio_interface(user_input, session_id):
|
| 213 |
-
# If session_id is not in session_ids, it's a new session
|
| 214 |
if session_id not in session_ids:
|
| 215 |
-
# Generate a new unique session ID
|
| 216 |
new_session_id = str(uuid.uuid4())
|
| 217 |
session_ids[session_id] = new_session_id
|
| 218 |
else:
|
| 219 |
new_session_id = session_ids[session_id]
|
| 220 |
-
|
| 221 |
result = agent_with_chat_history.invoke(
|
| 222 |
{"input": user_input},
|
| 223 |
config={"configurable": {"session_id": new_session_id}}
|
| 224 |
)
|
| 225 |
return [[user_input, result['output']]]
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
with gr.Blocks() as demo:
|
| 228 |
-
gr.Markdown("# Weather Assistant")
|
|
|
|
| 229 |
chatbot = gr.Chatbot()
|
|
|
|
| 230 |
with gr.Row():
|
| 231 |
txt = gr.Textbox(
|
| 232 |
show_label=False,
|
|
@@ -234,7 +262,17 @@ with gr.Blocks() as demo:
|
|
| 234 |
lines=1,
|
| 235 |
container=False
|
| 236 |
)
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
demo.launch(share=True)
|
|
|
|
| 16 |
from langchain_community.chat_message_histories import ChatMessageHistory
|
| 17 |
from langchain_core.runnables.history import RunnableWithMessageHistory
|
| 18 |
import gradio as gr
|
| 19 |
+
import base64
|
| 20 |
+
|
| 21 |
|
| 22 |
load_dotenv(dotenv_path='api.env.txt')
|
| 23 |
Langchain_API_KEY = os.getenv('LANGCHAIN_API')
|
|
|
|
| 212 |
session_ids = {}
|
| 213 |
|
| 214 |
def gradio_interface(user_input, session_id):
|
|
|
|
| 215 |
if session_id not in session_ids:
|
|
|
|
| 216 |
new_session_id = str(uuid.uuid4())
|
| 217 |
session_ids[session_id] = new_session_id
|
| 218 |
else:
|
| 219 |
new_session_id = session_ids[session_id]
|
| 220 |
+
|
| 221 |
result = agent_with_chat_history.invoke(
|
| 222 |
{"input": user_input},
|
| 223 |
config={"configurable": {"session_id": new_session_id}}
|
| 224 |
)
|
| 225 |
return [[user_input, result['output']]]
|
| 226 |
|
| 227 |
+
def encode_image(image_path):
|
| 228 |
+
with open(image_path, "rb") as image_file:
|
| 229 |
+
return base64.b64encode(image_file.read()).decode('utf-8')
|
| 230 |
+
|
| 231 |
+
# Encode the image
|
| 232 |
+
image_path = "/workspaces/Weather_Agent/productmanagerinterview_logo.jpeg"
|
| 233 |
+
encoded_image = encode_image(image_path)
|
| 234 |
+
|
| 235 |
+
info_text = f"""
|
| 236 |
+
<div style="display: flex; align-items: flex-start;">
|
| 237 |
+
<img src="data:image/jpeg;base64,{encoded_image}" alt="Logo" style="width: 200px; height: 200px; object-fit: cover; margin-right: 20px;">
|
| 238 |
+
<div>
|
| 239 |
+
<h2>Product Manager Accelerator Program</h2>
|
| 240 |
+
<p>The Product Manager Accelerator Program is designed to support PM professionals through every stage of their career. From students looking for entry-level jobs to Directors looking to take on a leadership role, our program has helped over hundreds of students fulfill their career aspirations.</p>
|
| 241 |
+
<p>Our Product Manager Accelerator community are ambitious and committed. Through our program they have learnt, honed and developed new PM and leadership skills, giving them a strong foundation for their future endeavours.</p>
|
| 242 |
+
<p>Learn product management for free today on our <a href="https://www.youtube.com/c/drnancyli?sub_confirmation=1" target="_blank">YouTube channel</a></p>
|
| 243 |
+
<h3>Interested in PM Accelerator Pro?</h3>
|
| 244 |
+
<ol>
|
| 245 |
+
<li>Attend the <a href="https://www.drnancyli.com/masterclass" target="_blank">Product Masterclass</a> to learn more about the program details, price, different packages, and stay until the end to get FREE AI Course. Learn how to create a killer product portfolio in two weeks that will help you land any PM job (traditional or AI) even if you were laid off or have zero PM experience.</li>
|
| 246 |
+
<li>Reserve your early bird ticket and submit an application to talk to our Head of Admission</li>
|
| 247 |
+
<li>Successful applicants join our PMA Pro community to receive customized coaching!</li>
|
| 248 |
+
</ol>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
"""
|
| 252 |
+
|
| 253 |
with gr.Blocks() as demo:
|
| 254 |
+
gr.Markdown("# Weather Assistant - Done By Mohamed Boghdady")
|
| 255 |
+
|
| 256 |
chatbot = gr.Chatbot()
|
| 257 |
+
|
| 258 |
with gr.Row():
|
| 259 |
txt = gr.Textbox(
|
| 260 |
show_label=False,
|
|
|
|
| 262 |
lines=1,
|
| 263 |
container=False
|
| 264 |
)
|
| 265 |
+
submit_btn = gr.Button("Submit")
|
| 266 |
+
|
| 267 |
+
session_id_box = gr.Textbox(visible=False, value=str(uuid.uuid4()))
|
| 268 |
+
|
| 269 |
+
# Add info button
|
| 270 |
+
info_btn = gr.Button("Info")
|
| 271 |
+
info_box = gr.HTML(visible=False, value=info_text)
|
| 272 |
+
|
| 273 |
+
# Set up event handlers
|
| 274 |
+
submit_btn.click(gradio_interface, inputs=[txt, session_id_box], outputs=chatbot)
|
| 275 |
+
txt.submit(gradio_interface, inputs=[txt, session_id_box], outputs=chatbot)
|
| 276 |
+
info_btn.click(lambda: gr.update(visible=True), outputs=info_box)
|
| 277 |
|
| 278 |
demo.launch(share=True)
|