dominguezdaniel commited on
Commit
759f312
·
verified ·
1 Parent(s): 57e302c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
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
- # Prepare a mockup tweet text
11
- tweet_text = f"Predicted Label: {top_prediction['label']}, Confidence: {top_prediction['score']:.2f}"
 
 
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 and generates a mock tweet with the top prediction."
16
  input_component = gr.Image(type="pil", label="Upload an image here")
17
- output_component = gr.Textbox(label="Mock Tweet")
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()