mrbeliever commited on
Commit
3dc8d07
·
verified ·
1 Parent(s): fb260dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -1,7 +1,9 @@
1
  import streamlit as st
2
- import requests
3
  import base64
 
4
  import os
 
 
5
 
6
  # Function to convert image to base64
7
  def convert_image_to_base64(image):
@@ -19,8 +21,8 @@ def generate_caption(encoded_image):
19
  "Content-Type": "application/json"
20
  }
21
 
22
- # Print base64 to debug (make sure it's different for each image upload)
23
- print(f"Base64 encoded image: {encoded_image[:100]}...") # Print only first 100 characters for brevity
24
 
25
  payload = {
26
  "model": "Qwen/Qwen2-VL-7B-Instruct",
@@ -37,7 +39,7 @@ def generate_caption(encoded_image):
37
  "image": {
38
  "type": "image_url",
39
  "image_url": {
40
- "url": f"data:image/png;base64,{encoded_image}"
41
  }
42
  },
43
  "temperature": 0
@@ -62,7 +64,7 @@ def main():
62
  st.markdown("Upload an image and let the AI generate a detailed caption for it.")
63
 
64
  uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
65
-
66
  if uploaded_file:
67
  # Display the uploaded image
68
  st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
@@ -71,7 +73,7 @@ def main():
71
  if st.button("Generate Caption"):
72
  with st.spinner("Generating caption..."):
73
  encoded_image = convert_image_to_base64(uploaded_file)
74
-
75
  # Debugging: print out the base64 string length to verify if it's changing
76
  st.write(f"Encoded image length: {len(encoded_image)} characters")
77
 
 
1
  import streamlit as st
 
2
  import base64
3
+ import requests
4
  import os
5
+ import random
6
+ import time
7
 
8
  # Function to convert image to base64
9
  def convert_image_to_base64(image):
 
21
  "Content-Type": "application/json"
22
  }
23
 
24
+ # Add a random string to the URL to prevent caching issues
25
+ random_string = str(random.randint(100000, 999999))
26
 
27
  payload = {
28
  "model": "Qwen/Qwen2-VL-7B-Instruct",
 
39
  "image": {
40
  "type": "image_url",
41
  "image_url": {
42
+ "url": f"data:image/png;base64,{encoded_image}?{random_string}" # Added random query to avoid cache
43
  }
44
  },
45
  "temperature": 0
 
64
  st.markdown("Upload an image and let the AI generate a detailed caption for it.")
65
 
66
  uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
67
+
68
  if uploaded_file:
69
  # Display the uploaded image
70
  st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
 
73
  if st.button("Generate Caption"):
74
  with st.spinner("Generating caption..."):
75
  encoded_image = convert_image_to_base64(uploaded_file)
76
+
77
  # Debugging: print out the base64 string length to verify if it's changing
78
  st.write(f"Encoded image length: {len(encoded_image)} characters")
79