Ashrafb commited on
Commit
9cc78ec
·
1 Parent(s): 68511b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -28
app.py CHANGED
@@ -1,34 +1,26 @@
1
  import streamlit as st
 
2
 
3
- # Load the model
4
- model = load_model('model.h5')
5
 
6
- # Define the input and output data
7
- input_data = st.text_input('Enter input data:')
8
- output_data = st.text_input('Enter output data:')
9
 
10
- # Define the prediction function
11
- def predict(input_data):
12
- # Preprocess the input data
13
- input_data = preprocess_input(input_data)
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
- # Create the Streamlit app
24
- st.title('Image Captioning App')
25
- st.write('Enter input data:')
26
- st.write(input_data)
27
- st.write('Enter output data:')
28
- st.write(output_data)
29
 
30
- # Add a button to make the prediction
31
- if st.button('Make Prediction'):
32
- output_data = predict(input_data)
33
- st.write('Predicted output:')
34
- st.write(output_data)
 
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)