Spaces:
Runtime error
Runtime error
Commit
·
f150cd0
0
Parent(s):
Duplicate from Xhaheen/meme_world
Browse files- .gitattributes +33 -0
- README.md +14 -0
- a boy is running with a soccer ball .png +0 -0
- a cat sitting on a desk next to a computer .png +0 -0
- a cat sitting on a table with a cake .png +0 -0
- a chair .png +0 -0
- a woman standing next to each other .png +0 -0
- jeans jumping a skateboard .png +0 -0
- tie .png +0 -0
- tie sitting at a desk .png +0 -0
- a man is using a laptop computer (2).png +0 -0
- a man is using a laptop computer .png +0 -0
- a man sitting at a table with a bottle of beer .png +0 -0
- a man sitting in a chair with a computer .png +0 -0
- a man sitting on a bench with a laptop .png +0 -0
- a woman sitting in front of a laptop computer .png +0 -0
- a young boy is smiling while using a laptop .png +0 -0
- a young boy sitting on the grass next to a lake .png +0 -0
- app.py +176 -0
- arial.ttf +0 -0
- example1.png +0 -0
- example2.png +0 -0
- example3.png +0 -0
- example4.png +0 -0
- example5.png +0 -0
- example6.png +0 -0
- requirements.txt +5 -0
.gitattributes
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
25 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Meme World
|
3 |
+
emoji: 📚
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: pink
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.6
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: Xhaheen/meme_world
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
a boy is running with a soccer ball .png
ADDED
|
a cat sitting on a desk next to a computer .png
ADDED
|
a cat sitting on a table with a cake .png
ADDED
|
a chair .png
RENAMED
File without changes
|
a woman standing next to each other .png
RENAMED
File without changes
|
jeans jumping a skateboard .png
RENAMED
File without changes
|
tie .png
RENAMED
File without changes
|
tie sitting at a desk .png
RENAMED
File without changes
|
a man is using a laptop computer (2).png
ADDED
![]() |
a man is using a laptop computer .png
ADDED
|
a man sitting at a table with a bottle of beer .png
ADDED
|
a man sitting in a chair with a computer .png
ADDED
|
a man sitting on a bench with a laptop .png
ADDED
|
a woman sitting in front of a laptop computer .png
ADDED
|
a young boy is smiling while using a laptop .png
ADDED
|
a young boy sitting on the grass next to a lake .png
ADDED
|
app.py
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# # %%bash
|
2 |
+
|
3 |
+
# # # git lfs install
|
4 |
+
# # # git clone https://huggingface.co/spaces/Xhaheen/meme_world
|
5 |
+
|
6 |
+
|
7 |
+
# # # pip install -r /content/meme_world/requirements.txt
|
8 |
+
# # # pip install gradio
|
9 |
+
# # cd /meme_world
|
10 |
+
|
11 |
+
|
12 |
+
# import torch
|
13 |
+
# import re
|
14 |
+
# import gradio as gr
|
15 |
+
# from transformers import AutoTokenizer, ViTFeatureExtractor, VisionEncoderDecoderModel
|
16 |
+
# import cohere
|
17 |
+
# import os
|
18 |
+
# #
|
19 |
+
# # os.environ['key_srkian'] = ''
|
20 |
+
# key_srkian = os.environ["key_srkian"]
|
21 |
+
# co = cohere.Client(key_srkian)#srkian
|
22 |
+
# device='cpu'
|
23 |
+
# encoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
24 |
+
# decoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
25 |
+
# model_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
26 |
+
# feature_extractor = ViTFeatureExtractor.from_pretrained(encoder_checkpoint)
|
27 |
+
# tokenizer = AutoTokenizer.from_pretrained(decoder_checkpoint)
|
28 |
+
# model = VisionEncoderDecoderModel.from_pretrained(model_checkpoint).to(device)
|
29 |
+
|
30 |
+
|
31 |
+
# def predict(department,image,max_length=64, num_beams=4):
|
32 |
+
# image = image.convert('RGB')
|
33 |
+
# image = feature_extractor(image, return_tensors="pt").pixel_values.to(device)
|
34 |
+
# clean_text = lambda x: x.replace('<|endoftext|>','').split('\n')[0]
|
35 |
+
# caption_ids = model.generate(image, max_length = max_length)[0]
|
36 |
+
# caption_text = clean_text(tokenizer.decode(caption_ids))
|
37 |
+
# dept=department
|
38 |
+
# context= caption_text
|
39 |
+
# response = co.generate(
|
40 |
+
# model='large',
|
41 |
+
# prompt=f'create non offensive one line meme for given department and context\n\ndepartment- data science\ncontext-a man sitting on a bench with a laptop\nmeme- \"I\'m not a data scientist, but I play one on my laptop.\"\n\ndepartment-startup\ncontext-a young boy is smiling while using a laptop\nmeme-\"When your startup gets funded and you can finally afford a new laptop\"\n\ndepartment- {dept}\ncontext-{context}\nmeme-',
|
42 |
+
# max_tokens=20,
|
43 |
+
# temperature=0.8,
|
44 |
+
# k=0,
|
45 |
+
# p=0.75,
|
46 |
+
# frequency_penalty=0,
|
47 |
+
# presence_penalty=0,
|
48 |
+
# stop_sequences=["department"],
|
49 |
+
# return_likelihoods='NONE')
|
50 |
+
# reponse=response.generations[0].text
|
51 |
+
# reponse = reponse.replace("department", "")
|
52 |
+
# Feedback_SQL="DEPT"+dept+"CAPT"+caption_text+"MAMAY"+reponse
|
53 |
+
|
54 |
+
|
55 |
+
# return reponse
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
# # input = gr.inputs.Image(label="Upload your Image", type = 'pil', optional=True)
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
# output = gr.outputs.Textbox(type="text",label="Meme")
|
64 |
+
# #examples = [f"example{i}.jpg" for i in range(1,7)]
|
65 |
+
# #examples = os.listdir()
|
66 |
+
# examples = [f"example{i}.png" for i in range(1,7)]
|
67 |
+
|
68 |
+
# #examples=os.listdir()
|
69 |
+
# #for fichier in examples:
|
70 |
+
# # if not(fichier.endswith(".png")):
|
71 |
+
# # examples.remove(fichier)
|
72 |
+
|
73 |
+
# description= " Looking for a fun and easy way to generate memes? Look no further than Meme world! Leveraging large language models like GPT-3PT-3 / Ai21 / Cohere, you can create memes that are sure to be a hit with your friends or network. Created with ♥️ by Arsalan @[Xaheen](https://www.linkedin.com/in/sallu-mandya/). kindly share your thoughts in discussion session and use the app responsibly #NO_Offense \n \n built with ❤️ @[Xhaheen](https://www.linkedin.com/in/sallu-mandya/)"
|
74 |
+
# title = "Meme world 🖼️"
|
75 |
+
# dropdown=["data science", "product management","marketing","startup" ,"agile","crypto" , "SEO" ]
|
76 |
+
|
77 |
+
# article = "Created By : Xaheen "
|
78 |
+
|
79 |
+
# interface = gr.Interface(
|
80 |
+
# fn=predict,
|
81 |
+
# inputs = [gr.inputs.Dropdown(dropdown),gr.inputs.Image(label="Upload your Image", type = 'pil', optional=True)],
|
82 |
+
|
83 |
+
# theme="grass",
|
84 |
+
# outputs=output,
|
85 |
+
# examples =[['data science', 'example5.png'],
|
86 |
+
# ['product management', 'example2.png'],
|
87 |
+
# ['startup', 'example3.png'],
|
88 |
+
# ['marketing', 'example4.png'],
|
89 |
+
# ['agile', 'example1.png'],
|
90 |
+
# ['crypto', 'example6.png']],
|
91 |
+
# title=title,
|
92 |
+
# description=description,
|
93 |
+
# article = article,
|
94 |
+
# )
|
95 |
+
# interface.launch(debug=True)
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
# Step 2: Set up the Gradio interface and import necessary packages
|
108 |
+
import gradio as gr
|
109 |
+
import openai
|
110 |
+
from transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer
|
111 |
+
import torch
|
112 |
+
from PIL import Image
|
113 |
+
|
114 |
+
# Step 3: Load the provided image captioning model
|
115 |
+
model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
116 |
+
feature_extractor = ViTImageProcessor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
117 |
+
tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
118 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
119 |
+
model.to(device)
|
120 |
+
|
121 |
+
# Step 4: Create a function to generate captions from images
|
122 |
+
max_length = 16
|
123 |
+
num_beams = 4
|
124 |
+
gen_kwargs = {"max_length": max_length, "num_beams": num_beams}
|
125 |
+
|
126 |
+
def generate_caption(image):
|
127 |
+
image = Image.fromarray(image.astype('uint8'), 'RGB')
|
128 |
+
if image.mode != "RGB":
|
129 |
+
image = image.convert(mode="RGB")
|
130 |
+
pixel_values = feature_extractor(images=[image], return_tensors="pt").pixel_values
|
131 |
+
pixel_values = pixel_values.to(device)
|
132 |
+
output_ids = model.generate(pixel_values, **gen_kwargs)
|
133 |
+
caption = tokenizer.decode(output_ids[0], skip_special_tokens=True).strip()
|
134 |
+
return caption
|
135 |
+
|
136 |
+
|
137 |
+
# Step 5: Create a function to generate memes using the GPT-3 API
|
138 |
+
def generate_meme(caption, department):
|
139 |
+
openai.api_key = os.environ["key"]
|
140 |
+
prompt = f"Create a non-offensive meme caption for the following image description in the context of {department} department: {caption}"
|
141 |
+
response = openai.Completion.create(engine="text-davinci-002", prompt=prompt, max_tokens=50, n=1, stop=None, temperature=0.7)
|
142 |
+
meme_caption = response.choices[0].text.strip()
|
143 |
+
return meme_caption
|
144 |
+
|
145 |
+
# Step 6: Define the main meme generation function
|
146 |
+
def meme_generator(image, department):
|
147 |
+
caption = generate_caption(image)
|
148 |
+
meme_caption = generate_meme(caption, department)
|
149 |
+
return meme_caption
|
150 |
+
|
151 |
+
examples = [f"example{i}.png" for i in range(1,7)]
|
152 |
+
|
153 |
+
# Step 7: Launch the Gradio application
|
154 |
+
image_input = gr.inputs.Image()
|
155 |
+
department_input = gr.inputs.Dropdown(choices=["data science", "product management","marketing","startup" ,"agile","crypto" , "SEO" ])
|
156 |
+
output_text = gr.outputs.Textbox()
|
157 |
+
|
158 |
+
gr.Interface(fn=meme_generator, inputs=[image_input, department_input], outputs=output_text, title="Meme world!",description= " Looking for a fun and easy way to generate memes? Look no further than Meme world! Leveraging large language models like GPT-3PT-3 / Ai21 / Cohere, you can create memes that are sure to be a hit with your friends or network. Created with ♥️ by Arsalan @[Xaheen](https://www.linkedin.com/in/sallu-mandya/). kindly share your thoughts in discussion session and use the app responsibly #NO_Offense \n \n built with ❤️ @[Xhaheen](https://www.linkedin.com/in/sallu-mandya/)", theme="grass",
|
159 |
+
|
160 |
+
examples =[['example5.png','data science' ],
|
161 |
+
['example2.png','product management'],
|
162 |
+
['example3.png','startup'],
|
163 |
+
['example4.png','marketing'],
|
164 |
+
['example1.png','agile'],
|
165 |
+
['example6.png','crypto']]).launch(debug=True)
|
166 |
+
|
167 |
+
|
168 |
+
|
169 |
+
|
170 |
+
|
171 |
+
|
172 |
+
|
173 |
+
|
174 |
+
|
175 |
+
|
176 |
+
|
arial.ttf
ADDED
Binary file (367 kB). View file
|
|
example1.png
ADDED
![]() |
example2.png
ADDED
![]() |
example3.png
ADDED
![]() |
example4.png
ADDED
![]() |
example5.png
ADDED
![]() |
example6.png
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
cohere
|
4 |
+
openai
|
5 |
+
Pillow
|