Adding report

main
Lasse Server 2 years ago
parent 4ff4d6722c
commit c5487cec6f
  1. BIN
      __pycache__/bot.cpython-39.pyc
  2. BIN
      __pycache__/bot_strings.cpython-39.pyc
  3. 2
      bot.py
  4. 28
      report_template.html
  5. 34
      streamlit_interface.py

Binary file not shown.

@ -148,7 +148,7 @@ class Chatbot(BaseBot):
return question
else:
return False, False
return 'done'
class CheckerBot(BaseBot):

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {font-family: Arial, Helvetica, sans-serif;}
h1 {color: #333;}
p {color: #666;}
</style>
</head>
<body>
<h1>Report by {{ report.name }}</h1>
<p><strong>Description:</strong> {{ report.description }}</p>
<p><strong>Incident:</strong> {{ report.incident }}</p>
<p><strong>Role:</strong> {{ report.role }}</p>
<p><strong>Location:</strong> {{ report.location }}</p>
<p><strong>Image:</strong> {{ report.image }}</p>
<p><strong>Size:</strong> {{ report.size }}</p>
<p><strong>Shape:</strong> {{ report.shape }}</p>
<p><strong>Color:</strong> {{ report.color }}</p>
<p><strong>Organization:</strong> {{ report.organization }}</p>
<p><strong>Type:</strong> {{ report.type }}</p>
<p><strong>Marked:</strong> {{ report.marked }}</p>
<p><strong>Blockage:</strong> {{ report.blockage }}</p>
<p><strong>Area Description:</strong> {{ report.area_description }}</p>
<p><strong>Contact Person Phone Number:</strong> {{ report.contact_person_phone_number }}</p>
<p><strong>Contact Person Name:</strong> {{ report.contact_person_name }}</p>
</body>
</html>

@ -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)

Loading…
Cancel
Save