Spaces:
Build error
Build error
Update app.py
Browse filescaption image start
app.py
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
fuyu_client = Client("https://adept-fuyu-8b-demo.hf.space/")
|
| 4 |
+
def get_caption(image_in):
|
| 5 |
+
|
| 6 |
+
fuyu_result = fuyu_client.predict(
|
| 7 |
+
image_in, # str representing input in 'raw_image' Image component
|
| 8 |
+
True, # bool in 'Enable detailed captioning' Checkbox component
|
| 9 |
+
fn_index=2
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
# Find the last occurrence of "."
|
| 13 |
+
last_period_index = fuyu_result.rfind('.')
|
| 14 |
+
|
| 15 |
+
# Truncate the string up to the last period
|
| 16 |
+
truncated_caption = fuyu_result[:last_period_index + 1]
|
| 17 |
+
|
| 18 |
+
# print(truncated_caption)
|
| 19 |
+
print(f"\n—\nIMAGE CAPTION: {truncated_caption}")
|
| 20 |
+
|
| 21 |
+
return truncated_caption
|
| 22 |
+
|
| 23 |
+
uploaded_image = st.file_uploader("Drag and drop an image here, or click to select one", type=["png", "jpg", "jpeg"])
|
| 24 |
+
|
| 25 |
+
# Display the uploaded image
|
| 26 |
+
if uploaded_image is not None:
|
| 27 |
+
# Read the image
|
| 28 |
+
image = Image.open(uploaded_image)
|
| 29 |
+
|
| 30 |
+
# Display the image
|
| 31 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 32 |
+
|
| 33 |
+
st.write(truncated_caption)
|