Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,13 +7,15 @@ def predict(image):
|
|
7 |
predictions = classifier(image)
|
8 |
# Sort predictions based on confidence and select the top one
|
9 |
top_prediction = sorted(predictions, key=lambda x: x['score'], reverse=True)[0]
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
return tweet_text
|
13 |
|
14 |
-
title = "Image Classifier to Tweet"
|
15 |
-
description = "This demo recognizes and classifies images using the 'google/vit-base-patch16-224' model
|
16 |
input_component = gr.Image(type="pil", label="Upload an image here")
|
17 |
-
output_component = gr.Textbox(label="
|
18 |
|
19 |
gr.Interface(fn=predict, inputs=input_component, outputs=output_component, title=title, description=description).launch()
|
|
|
7 |
predictions = classifier(image)
|
8 |
# Sort predictions based on confidence and select the top one
|
9 |
top_prediction = sorted(predictions, key=lambda x: x['score'], reverse=True)[0]
|
10 |
+
|
11 |
+
# Generate a promotional tweet based on the top prediction
|
12 |
+
tweet_template = "Check out this amazing {label}! 📸✨ Explore more about it and let your curiosity lead you to discover wonders."
|
13 |
+
tweet_text = tweet_template.format(label=top_prediction['label'].split(',')[0]) # Using split to clean up label if necessary
|
14 |
return tweet_text
|
15 |
|
16 |
+
title = "Image Classifier to Promotional Tweet"
|
17 |
+
description = "This demo recognizes and classifies images using the 'google/vit-base-patch16-224' model. Below, you'll see a generated promotional tweet based on the top prediction. Your task: Upload an image, and let's write a tweet about it!"
|
18 |
input_component = gr.Image(type="pil", label="Upload an image here")
|
19 |
+
output_component = gr.Textbox(label="Generated Promotional Tweet", placeholder="Write a tweet about the image")
|
20 |
|
21 |
gr.Interface(fn=predict, inputs=input_component, outputs=output_component, title=title, description=description).launch()
|