dominguezdaniel commited on
Commit
cba370e
1 Parent(s): 30133f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -1,16 +1,16 @@
1
  import gradio as gr
2
- from transformers import pipeline, GPT2Tokenizer, GPT2LMHeadModel
3
 
4
  # Initialize the image classification pipeline
5
  classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
6
 
7
- # Initialize the tokenizer and model for the generative text (GPT-like model)
8
- model_name = "gpt2" # Use GPT-2 model for demonstration
9
- tokenizer = GPT2Tokenizer.from_pretrained(model_name)
10
- model = GPT2LMHeadModel.from_pretrained(model_name)
11
 
12
  def generate_tweet(label):
13
- # Craft a prompt that naturally encourages engaging and relevant tweet content
14
  prompt = f"write a tweet about {label}"
15
 
16
  inputs = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=True)
@@ -31,7 +31,7 @@ def predict(image):
31
  return tweet
32
 
33
  title = "Image Classifier to Generative Tweet"
34
- description = "This demo recognizes and classifies images using the 'google/vit-base-patch16-224' model and generates a tweet about the top prediction using GPT-2 for generating creative and engaging content."
35
  input_component = gr.Image(type="pil", label="Upload an image here")
36
  output_component = gr.Textbox(label="Generated Promotional Tweet")
37
 
 
1
  import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
3
 
4
  # Initialize the image classification pipeline
5
  classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
6
 
7
+ # Initialize the tokenizer and model for the generative text
8
+ model_name = "EleutherAI/gpt-neo-2.7B" # Using GPT-Neo for demonstration
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ model = AutoModelForCausalLM.from_pretrained(model_name)
11
 
12
  def generate_tweet(label):
13
+ # Generate a tweet about the label
14
  prompt = f"write a tweet about {label}"
15
 
16
  inputs = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=True)
 
31
  return tweet
32
 
33
  title = "Image Classifier to Generative Tweet"
34
+ description = "This demo recognizes and classifies images using the 'google/vit-base-patch16-224' model and generates a tweet about the top prediction using the GPT-Neo model for generating creative and engaging content."
35
  input_component = gr.Image(type="pil", label="Upload an image here")
36
  output_component = gr.Textbox(label="Generated Promotional Tweet")
37