Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -103,7 +103,54 @@ def predict_answer(image, video, question):
|
|
| 103 |
else:
|
| 104 |
return "Unsupported file type. Please upload an image or video."
|
| 105 |
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
|
| 109 |
def gradio_predict(image, video, question):
|
|
@@ -147,5 +194,15 @@ with gr.Blocks(css = css) as app:
|
|
| 147 |
|
| 148 |
btn.click(gradio_predict, inputs=[image, video, question], outputs=answer)
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
app.launch(debug=True)
|
| 151 |
|
|
|
|
| 103 |
else:
|
| 104 |
return "Unsupported file type. Please upload an image or video."
|
| 105 |
|
| 106 |
+
promt_cat_dog = """
|
| 107 |
+
Annotate this image with this schema:
|
| 108 |
+
{
|
| 109 |
+
“description”: “Is there a cat in the image?”,
|
| 110 |
+
“value”: “Cat”
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
“description”: “Is there a dog in the image?”,
|
| 114 |
+
“value”: “Dog”
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
“description”: “Is there a horse in the image?”,
|
| 118 |
+
“value”: “Horse”
|
| 119 |
+
},
|
| 120 |
+
|
| 121 |
+
provide me the answers as a dictionary with key as the string value of the variable value on top and its value should be 0 if it is Flase, else 1 if its is True
|
| 122 |
+
"""
|
| 123 |
+
promt_bus_people = """
|
| 124 |
+
Annotate this image with this schema:
|
| 125 |
+
{
|
| 126 |
+
“description”: “Is there a bus in the image?”,
|
| 127 |
+
“value”: “Bus”
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
“description”: “Is there a bike in the image?”,
|
| 131 |
+
“value”: “Bike”
|
| 132 |
+
},
|
| 133 |
+
|
| 134 |
+
provide me the answers as a dictionary with key as the string value of the variable value on top and its value should be 0 if it is Flase, else 1 if its is True
|
| 135 |
+
"""
|
| 136 |
+
|
| 137 |
+
promt_video = """
|
| 138 |
+
Annotate this image with this schema:
|
| 139 |
+
{
|
| 140 |
+
“description”: “Is the person standing?”,
|
| 141 |
+
“value”: “Standing”
|
| 142 |
+
},
|
| 143 |
+
{
|
| 144 |
+
“description”: “Is the person hands free?”,
|
| 145 |
+
“value”: “Hands-Free”
|
| 146 |
+
}
|
| 147 |
+
provide me the answers as a dictionary with key as the string value of the variable value on top and its value should be 0 if it is Flase, else 1 if its is True
|
| 148 |
+
"""
|
| 149 |
+
test_examples = [[None, "Images/cat_dog.jpeg", promt_cat_dog],
|
| 150 |
+
[None,"Images/bus_people.jpeg", promt_bus_people],
|
| 151 |
+
["videos/v1.mp4",None,promt_video],
|
| 152 |
+
["videos/v2.mp4",None,promt_video],
|
| 153 |
+
["videos/v3.mp4",None,promt_video]]
|
| 154 |
|
| 155 |
|
| 156 |
def gradio_predict(image, video, question):
|
|
|
|
| 194 |
|
| 195 |
btn.click(gradio_predict, inputs=[image, video, question], outputs=answer)
|
| 196 |
|
| 197 |
+
# Define examples for images
|
| 198 |
+
gr.Markdown("## Examples")
|
| 199 |
+
gr.Examples(
|
| 200 |
+
examples=test_examples,
|
| 201 |
+
inputs=[image, video, question],
|
| 202 |
+
outputs=[answer],
|
| 203 |
+
fn=gradio_predict,
|
| 204 |
+
cache_examples=True,
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
app.launch(debug=True)
|
| 208 |
|