vam
commited on
Commit
•
c0a0cd2
1
Parent(s):
6ebae13
Update app.py
Browse files
app.py
CHANGED
@@ -11,13 +11,8 @@ import os
|
|
11 |
api_key = os.getenv("YOUR_OPENAI_KEY")
|
12 |
openai.api_key = api_key
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
["Generate me a funny meme about friends"],
|
17 |
-
["Create a caption for a sad meme about exams"]
|
18 |
-
]
|
19 |
-
|
20 |
-
# Function to generate meme caption using GPT model
|
21 |
def generate_meme_caption(topic):
|
22 |
response = openai.ChatCompletion.create(
|
23 |
model="gpt-4o-mini",
|
@@ -87,20 +82,14 @@ with gr.Blocks() as demo:
|
|
87 |
prompt = gr.Textbox(label="Enter your meme prompt:")
|
88 |
run_button = gr.Button("Generate Meme")
|
89 |
|
90 |
-
result = gr.
|
91 |
-
download_button = gr.File(label="Download Meme") # Thêm nút download
|
92 |
|
93 |
-
# Function to call Gradio infer
|
94 |
def gradio_infer(prompt):
|
95 |
plt.figure(figsize=(10, 8))
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
gr.Examples(
|
100 |
-
examples=examples,
|
101 |
-
inputs=[prompt]
|
102 |
-
)
|
103 |
|
104 |
-
run_button.click(gradio_infer, inputs=[prompt], outputs=[result
|
105 |
|
106 |
-
demo.launch()
|
|
|
11 |
api_key = os.getenv("YOUR_OPENAI_KEY")
|
12 |
openai.api_key = api_key
|
13 |
|
14 |
+
# Function to generate meme caption using GPT4o mini model
|
15 |
+
#GPT 4o-mini is cheap
|
|
|
|
|
|
|
|
|
|
|
16 |
def generate_meme_caption(topic):
|
17 |
response = openai.ChatCompletion.create(
|
18 |
model="gpt-4o-mini",
|
|
|
82 |
prompt = gr.Textbox(label="Enter your meme prompt:")
|
83 |
run_button = gr.Button("Generate Meme")
|
84 |
|
85 |
+
result = gr.Plot(label="Generated Meme")
|
|
|
86 |
|
|
|
87 |
def gradio_infer(prompt):
|
88 |
plt.figure(figsize=(10, 8))
|
89 |
+
create_meme(prompt)
|
90 |
+
plt.savefig('/tmp/meme.png') # Lưu hình tạm thời
|
91 |
+
return plt
|
|
|
|
|
|
|
|
|
92 |
|
93 |
+
run_button.click(gradio_infer, inputs=[prompt], outputs=[result])
|
94 |
|
95 |
+
demo.launch()
|