Spaces:
Sleeping
Sleeping
dominguezdaniel
commited on
Commit
•
cba370e
1
Parent(s):
30133f5
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline,
|
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 = "
|
9 |
-
tokenizer =
|
10 |
-
model =
|
11 |
|
12 |
def generate_tweet(label):
|
13 |
-
#
|
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-
|
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 |
|