dominguezdaniel commited on
Commit
30133f5
·
verified ·
1 Parent(s): 1959014

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -1,19 +1,19 @@
1
  import gradio as gr
2
- from transformers import pipeline, BartTokenizer, BartForConditionalGeneration
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 = "textattack/facebook-bart-base-RTE" # Example BART model for demonstration
9
- tokenizer = BartTokenizer.from_pretrained(model_name)
10
- model = BartForConditionalGeneration.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")
17
  outputs = model.generate(inputs, max_length=280, num_return_sequences=1, no_repeat_ngram_size=2)
18
 
19
  tweet = tokenizer.decode(outputs[0], skip_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 the 'facebook/bart-large-cnn' generative text model."
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, 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)
17
  outputs = model.generate(inputs, max_length=280, num_return_sequences=1, no_repeat_ngram_size=2)
18
 
19
  tweet = tokenizer.decode(outputs[0], skip_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 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