Fix memory initialization and add image conversion to Base64

main
Lasse Server 2 years ago
parent 49df3b653e
commit 1d8ebbb25b
  1. 2
      bot.py
  2. 2
      report_template.html
  3. 10
      streamlit_interface.py

@ -167,7 +167,7 @@ class Chatbot(BaseBot):
prompt = f"Formulate a question asking for the following information: {looking_for}"
general_bot.memory.append({"role": "user", "content": prompt})
question = general_bot.generate(prompt)["content"]
general_bot.memory = None
general_bot.memory =[]
return question
else:

@ -13,7 +13,7 @@
<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>Image:</strong> <img src="data:image/jpeg;base64,{{ report.image }}" alt="Report Image"></p>
<p><strong>Size:</strong> {{ report.size }}</p>
<p><strong>Shape:</strong> {{ report.shape }}</p>
<p><strong>Color:</strong> {{ report.color }}</p>

@ -111,6 +111,8 @@ if st.session_state.report_html != '':
# Check if 'upload_image' is set to True in the session state
if st.session_state.upload_image:
import base64
from io import BytesIO
# Initialize user_input to None
user_input = None
# Create a file uploader widget that accepts png, jpg, and jpeg files
@ -122,7 +124,13 @@ if st.session_state.upload_image:
# Open the image file and convert it to a numpy array and store the image array in the report object
image = Image.open(img_file)
img_array = np.array(image)
report.image = img_array
# Convert the image to Base64
buffered = BytesIO()
image.save(buffered, format="JPEG")
img_str = base64.b64encode(buffered.getvalue()).decode()
report.image = img_str
send('Thanks!', check=False, add_to_memory=False)
# Ask the chatbot for more information and store the question
question = chatbot.ask_for_info(report, chatbot=chatbot)

Loading…
Cancel
Save