Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,7 @@ def generate_caption(encoded_image):
|
|
20 |
}
|
21 |
|
22 |
payload = {
|
23 |
-
"model": "
|
24 |
"messages": [
|
25 |
{
|
26 |
"role": "system",
|
@@ -37,11 +37,11 @@ def generate_caption(encoded_image):
|
|
37 |
"url": f"data:image/png;base64,{encoded_image}"
|
38 |
}
|
39 |
},
|
40 |
-
"temperature": 0
|
41 |
}
|
42 |
|
43 |
response = requests.post(API_URL, headers=headers, json=payload)
|
44 |
-
|
45 |
if response.status_code == 200:
|
46 |
result = response.json()
|
47 |
caption = result.get("choices", [{}])[0].get("message", {}).get("content", "No caption generated.")
|
@@ -53,35 +53,9 @@ def generate_caption(encoded_image):
|
|
53 |
# Streamlit app
|
54 |
def main():
|
55 |
st.set_page_config(page_title="Image to Caption Converter", layout="centered", initial_sidebar_state="collapsed")
|
56 |
-
|
57 |
-
# Gradient background style
|
58 |
-
st.markdown("""
|
59 |
-
<style>
|
60 |
-
body {
|
61 |
-
background: linear-gradient(135deg, #1e3c72, #2a5298);
|
62 |
-
color: white;
|
63 |
-
font-family: 'Arial', sans-serif;
|
64 |
-
}
|
65 |
-
.uploaded-image {
|
66 |
-
max-width: 100%;
|
67 |
-
border: 2px solid #ffffff;
|
68 |
-
border-radius: 10px;
|
69 |
-
}
|
70 |
-
.copy-button {
|
71 |
-
background-color: #ff8800;
|
72 |
-
color: white;
|
73 |
-
border: none;
|
74 |
-
border-radius: 5px;
|
75 |
-
padding: 10px 15px;
|
76 |
-
cursor: pointer;
|
77 |
-
}
|
78 |
-
.copy-button:hover {
|
79 |
-
background-color: #cc6b00;
|
80 |
-
}
|
81 |
-
</style>
|
82 |
-
""", unsafe_allow_html=True)
|
83 |
|
84 |
st.title("🖼️ Image to Caption Converter")
|
|
|
85 |
|
86 |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
87 |
if uploaded_file:
|
@@ -99,9 +73,7 @@ def main():
|
|
99 |
st.text_area("", caption, height=100, key="caption_area")
|
100 |
|
101 |
# Copy button
|
102 |
-
|
103 |
-
st.code(caption, language="text")
|
104 |
-
st.success("Caption copied to clipboard!")
|
105 |
|
106 |
if __name__ == "__main__":
|
107 |
main()
|
|
|
20 |
}
|
21 |
|
22 |
payload = {
|
23 |
+
"model": "Qwen/Qwen2-VL-7B-Instruct",
|
24 |
"messages": [
|
25 |
{
|
26 |
"role": "system",
|
|
|
37 |
"url": f"data:image/png;base64,{encoded_image}"
|
38 |
}
|
39 |
},
|
40 |
+
"temperature": 0
|
41 |
}
|
42 |
|
43 |
response = requests.post(API_URL, headers=headers, json=payload)
|
44 |
+
|
45 |
if response.status_code == 200:
|
46 |
result = response.json()
|
47 |
caption = result.get("choices", [{}])[0].get("message", {}).get("content", "No caption generated.")
|
|
|
53 |
# Streamlit app
|
54 |
def main():
|
55 |
st.set_page_config(page_title="Image to Caption Converter", layout="centered", initial_sidebar_state="collapsed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
st.title("🖼️ Image to Caption Converter")
|
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:
|
|
|
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__":
|
79 |
main()
|