Update app.py
Browse files
app.py
CHANGED
|
@@ -13,46 +13,22 @@ def predict(image):
|
|
| 13 |
guess1, guess2 = cal_est[0]['answer'], cal_est[1]['answer']
|
| 14 |
return f"This is {type_food[0]['answer']}. I estimate this to contain {min(guess1, guess2)}-{max(guess1, guess2)} calories"
|
| 15 |
oracle = pipeline(model="dandelin/vilt-b32-finetuned-vqa")
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
h3#header {
|
| 21 |
-
text-align: center;
|
| 22 |
-
}
|
| 23 |
-
img#overview {
|
| 24 |
-
max-width: 800px;
|
| 25 |
-
max-height: 600px;
|
| 26 |
-
}
|
| 27 |
-
img#style-image {
|
| 28 |
-
max-width: 1000px;
|
| 29 |
-
max-height: 600px;
|
| 30 |
-
}
|
| 31 |
-
'''
|
| 32 |
-
demo = gr.Blocks(css=css)
|
| 33 |
-
with demo:
|
| 34 |
-
gr.Markdown('''<h1 id="title">Image Caption 🖼️</h1>''')
|
| 35 |
-
gr.Markdown('''Made by : ''')
|
| 36 |
-
with gr.Column():
|
| 37 |
-
input = gr.inputs.Image(label="Upload your Image", type = 'pil', optional=True)
|
| 38 |
-
output = gr.outputs.Textbox(type="auto",label="Captions")
|
| 39 |
-
btn = gr.Button("Genrate Caption")
|
| 40 |
-
btn.click(fn=predict, inputs=input, outputs=output)
|
| 41 |
-
demo.launch()
|
| 42 |
-
# def main():
|
| 43 |
-
# st.title("Image Question Answering App")
|
| 44 |
-
# st.write("Upload an image and ask a question to get answers!")
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
#
|
| 50 |
-
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
|
|
|
| 13 |
guess1, guess2 = cal_est[0]['answer'], cal_est[1]['answer']
|
| 14 |
return f"This is {type_food[0]['answer']}. I estimate this to contain {min(guess1, guess2)}-{max(guess1, guess2)} calories"
|
| 15 |
oracle = pipeline(model="dandelin/vilt-b32-finetuned-vqa")
|
| 16 |
+
|
| 17 |
+
def main():
|
| 18 |
+
st.title("Image Question Answering App")
|
| 19 |
+
st.write("Upload an image and ask a question to get answers!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
oracle = pipeline(model="dandelin/vilt-b32-finetuned-vqa")
|
| 22 |
|
| 23 |
+
while True:
|
| 24 |
+
# File uploader for image
|
| 25 |
+
uploaded_image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
| 26 |
|
| 27 |
+
if uploaded_image is not None:
|
| 28 |
+
image = Image.open(uploaded_image)
|
| 29 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 30 |
+
response = predict(image)
|
| 31 |
+
st.write(response)
|
| 32 |
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
main()
|