Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,26 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
model = load_model('model.h5')
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
output_data = st.text_input('Enter output data:')
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
# Make the prediction
|
| 16 |
-
output_data = model.predict(input_data)
|
| 17 |
-
|
| 18 |
-
# Postprocess the output data
|
| 19 |
-
output_data = postprocess_output(output_data)
|
| 20 |
-
|
| 21 |
-
return output_data
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
st.write(
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
|
| 4 |
+
st.title("Image Captioning App")
|
|
|
|
| 5 |
|
| 6 |
+
# Create a file uploader widget
|
| 7 |
+
uploaded_file = st.file_uploader("Choose an image file", type="image/*")
|
|
|
|
| 8 |
|
| 9 |
+
# If a file is uploaded, send a POST request to the API endpoint
|
| 10 |
+
if uploaded_file is not None:
|
| 11 |
+
# Read the image file as a base64 encoded string
|
| 12 |
+
image_data = uploaded_file.read()
|
| 13 |
+
image_data = base64.b64encode(image_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Send a POST request to the API endpoint with the image data as the payload
|
| 16 |
+
response = requests.post("https://ashrafb-salesforce-blip-image-captioning-base.hf.space/run/predict", json={
|
| 17 |
+
"data": [
|
| 18 |
+
image_data,
|
| 19 |
+
]
|
| 20 |
+
})
|
| 21 |
|
| 22 |
+
# Extract the generated caption from the response
|
| 23 |
+
caption = response.json()["data"][0]
|
| 24 |
+
|
| 25 |
+
# Display the generated caption
|
| 26 |
+
st.write(caption)
|