Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -138,10 +138,9 @@ def process_text(user_name, text_input):
|
|
| 138 |
|
| 139 |
# Function to process image
|
| 140 |
def process_image(user_name, image_input, user_prompt):
|
| 141 |
-
|
| 142 |
-
with open(image_input, "rb") as image_file:
|
| 143 |
-
image_input = image_file.read()
|
| 144 |
base64_image = base64.b64encode(image_input).decode("utf-8")
|
|
|
|
| 145 |
response = client.chat.completions.create(
|
| 146 |
model=MODEL,
|
| 147 |
messages=[
|
|
@@ -154,11 +153,19 @@ def process_image(user_name, image_input, user_prompt):
|
|
| 154 |
temperature=0.0,
|
| 155 |
)
|
| 156 |
image_response = response.choices[0].message.content
|
| 157 |
-
|
| 158 |
timestamp = datetime.now(pytz.utc).strftime('%Y-%m-%d %H:%M:%S %Z')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
filename_md = generate_filename(user_prompt, "md")
|
| 160 |
create_file(filename_md, user_prompt, image_response, user_name, timestamp)
|
| 161 |
-
st.session_state.messages.append({"user": user_name, "message": image_response, "timestamp": timestamp})
|
| 162 |
save_data()
|
| 163 |
return image_response
|
| 164 |
|
|
|
|
| 138 |
|
| 139 |
# Function to process image
|
| 140 |
def process_image(user_name, image_input, user_prompt):
|
| 141 |
+
image = Image.open(BytesIO(image_input))
|
|
|
|
|
|
|
| 142 |
base64_image = base64.b64encode(image_input).decode("utf-8")
|
| 143 |
+
|
| 144 |
response = client.chat.completions.create(
|
| 145 |
model=MODEL,
|
| 146 |
messages=[
|
|
|
|
| 153 |
temperature=0.0,
|
| 154 |
)
|
| 155 |
image_response = response.choices[0].message.content
|
| 156 |
+
|
| 157 |
timestamp = datetime.now(pytz.utc).strftime('%Y-%m-%d %H:%M:%S %Z')
|
| 158 |
+
st.session_state.messages.append({"user": user_name, "message": image_response, "timestamp": timestamp})
|
| 159 |
+
|
| 160 |
+
with st.chat_message(user_name):
|
| 161 |
+
st.image(image)
|
| 162 |
+
st.markdown(f"{user_name} ({timestamp}): {user_prompt}")
|
| 163 |
+
|
| 164 |
+
with st.chat_message("Assistant"):
|
| 165 |
+
st.markdown(image_response)
|
| 166 |
+
|
| 167 |
filename_md = generate_filename(user_prompt, "md")
|
| 168 |
create_file(filename_md, user_prompt, image_response, user_name, timestamp)
|
|
|
|
| 169 |
save_data()
|
| 170 |
return image_response
|
| 171 |
|