mrbeliever commited on
Commit
fb260dd
·
verified ·
1 Parent(s): 47ad849

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -19,6 +19,9 @@ def generate_caption(encoded_image):
19
  "Content-Type": "application/json"
20
  }
21
 
 
 
 
22
  payload = {
23
  "model": "Qwen/Qwen2-VL-7B-Instruct",
24
  "messages": [
@@ -40,6 +43,7 @@ def generate_caption(encoded_image):
40
  "temperature": 0
41
  }
42
 
 
43
  response = requests.post(API_URL, headers=headers, json=payload)
44
 
45
  if response.status_code == 200:
@@ -58,6 +62,7 @@ def main():
58
  st.markdown("Upload an image and let the AI generate a detailed caption for it.")
59
 
60
  uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
 
61
  if uploaded_file:
62
  # Display the uploaded image
63
  st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
@@ -66,13 +71,17 @@ def main():
66
  if st.button("Generate Caption"):
67
  with st.spinner("Generating caption..."):
68
  encoded_image = convert_image_to_base64(uploaded_file)
 
 
 
 
69
  caption = generate_caption(encoded_image)
70
 
71
  if caption:
72
  st.subheader("Generated Caption:")
73
  st.text_area("", caption, height=100, key="caption_area")
74
 
75
- # Copy button
76
  st.button("Copy to Clipboard", on_click=lambda: st.session_state.update({"caption": caption}))
77
 
78
  if __name__ == "__main__":
 
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",
27
  "messages": [
 
43
  "temperature": 0
44
  }
45
 
46
+ # Send request to API
47
  response = requests.post(API_URL, headers=headers, json=payload)
48
 
49
  if response.status_code == 200:
 
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
  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
+
78
  caption = generate_caption(encoded_image)
79
 
80
  if caption:
81
  st.subheader("Generated Caption:")
82
  st.text_area("", caption, height=100, key="caption_area")
83
 
84
+ # Copy button (if you want to implement this, use st.session_state)
85
  st.button("Copy to Clipboard", on_click=lambda: st.session_state.update({"caption": caption}))
86
 
87
  if __name__ == "__main__":