diff --git a/__pycache__/bot.cpython-39.pyc b/__pycache__/bot.cpython-39.pyc new file mode 100644 index 0000000..d750115 Binary files /dev/null and b/__pycache__/bot.cpython-39.pyc differ diff --git a/__pycache__/bot_strings.cpython-39.pyc b/__pycache__/bot_strings.cpython-39.pyc new file mode 100644 index 0000000..292a15f Binary files /dev/null and b/__pycache__/bot_strings.cpython-39.pyc differ diff --git a/bot.py b/bot.py index fe13e57..76ef349 100644 --- a/bot.py +++ b/bot.py @@ -148,7 +148,7 @@ class Chatbot(BaseBot): return question else: - return False, False + return 'done' class CheckerBot(BaseBot): diff --git a/report_template.html b/report_template.html new file mode 100644 index 0000000..21d22b7 --- /dev/null +++ b/report_template.html @@ -0,0 +1,28 @@ + + +
+ + + +Description: {{ report.description }}
+Incident: {{ report.incident }}
+Role: {{ report.role }}
+Location: {{ report.location }}
+Image: {{ report.image }}
+Size: {{ report.size }}
+Shape: {{ report.shape }}
+Color: {{ report.color }}
+Organization: {{ report.organization }}
+Type: {{ report.type }}
+Marked: {{ report.marked }}
+Blockage: {{ report.blockage }}
+Area Description: {{ report.area_description }}
+Contact Person Phone Number: {{ report.contact_person_phone_number }}
+Contact Person Name: {{ report.contact_person_name }}
+ + \ No newline at end of file diff --git a/streamlit_interface.py b/streamlit_interface.py index 33d43a8..a065bbb 100644 --- a/streamlit_interface.py +++ b/streamlit_interface.py @@ -1,4 +1,5 @@ import streamlit as st +import json import numpy as np from PIL import Image from bot import Chatbot, Report, CheckerBot, GeneralBot, botstrings @@ -29,6 +30,24 @@ def store_state(): st.session_state.report = report +def generate_report(): + from jinja2 import Environment, FileSystemLoader + + # Load the Jinja2 template + env = Environment(loader=FileSystemLoader('.')) + template = env.get_template('report_template.html') + + return template.render(report=report) + + +def report_button(): + if st.button("Generate report"): + report = st.session_state.report + report_html = generate_report(report) + st.markdown(report_html, unsafe_allow_html=True) + + + st.title("UNMAS Bot") # Initialize chat history @@ -65,7 +84,7 @@ for message in st.session_state.messages: with st.chat_message(message["role"]): st.markdown(message["content"]) - +print('Upload image', st.session_state.upload_image) if st.session_state.upload_image: user_input = None img_file = st.file_uploader('Upload an image', type=['png', 'jpg', 'jpeg']) @@ -79,6 +98,7 @@ if st.session_state.upload_image: send(question, check=False) st.session_state.upload_image = False store_state() + st.rerun() # user_input = st.chat_input('') @@ -93,6 +113,10 @@ else: if user_input and not st.session_state.upload_image: + if user_input.lower() == 'show report': + # Download the report + report_button() + st.chat_message("user").markdown(user_input) # Add user message to chat history st.session_state.messages.append({"role": "user", "content": user_input}) @@ -148,6 +172,14 @@ if user_input and not st.session_state.upload_image: print(st.session_state.upload_image) send(question, check=False, add_to_memory=False) st.rerun() + + elif question == 'done': + send('Thank you for your help! I will now process the information and get back to you. Below is the report.', check=False) + r = report.__dict__.copy() + del r['descriptions'] + del r['image'] + st.write(json.dumps(r, indent=4)) + else: send(question, check=False)