vam
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,12 @@ import os
|
|
| 11 |
api_key = os.getenv("YOUR_OPENAI_KEY")
|
| 12 |
openai.api_key = api_key
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Function to generate meme caption using GPT model
|
| 15 |
def generate_meme_caption(topic):
|
| 16 |
response = openai.ChatCompletion.create(
|
|
@@ -81,14 +87,20 @@ with gr.Blocks() as demo:
|
|
| 81 |
prompt = gr.Textbox(label="Enter your meme prompt:")
|
| 82 |
run_button = gr.Button("Generate Meme")
|
| 83 |
|
| 84 |
-
result = gr.
|
|
|
|
| 85 |
|
|
|
|
| 86 |
def gradio_infer(prompt):
|
| 87 |
plt.figure(figsize=(10, 8))
|
| 88 |
-
create_meme(prompt)
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
run_button.click(gradio_infer, inputs=[prompt], outputs=[result])
|
| 93 |
|
| 94 |
demo.launch()
|
|
|
|
| 11 |
api_key = os.getenv("YOUR_OPENAI_KEY")
|
| 12 |
openai.api_key = api_key
|
| 13 |
|
| 14 |
+
examples = [
|
| 15 |
+
["Explain something dark but unknown about space"],
|
| 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(
|
|
|
|
| 87 |
prompt = gr.Textbox(label="Enter your meme prompt:")
|
| 88 |
run_button = gr.Button("Generate Meme")
|
| 89 |
|
| 90 |
+
result = gr.Image(label="Generated Meme", show_label=False)
|
| 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 |
+
combined_img, output_path = create_meme(prompt)
|
| 97 |
+
return combined_img, output_path # Trả về ảnh và đường dẫn file tải xuống
|
| 98 |
+
|
| 99 |
+
gr.Examples(
|
| 100 |
+
examples=examples,
|
| 101 |
+
inputs=[prompt]
|
| 102 |
+
)
|
| 103 |
|
| 104 |
+
run_button.click(gradio_infer, inputs=[prompt], outputs=[result, download_button]) # Thêm download_button vào outputs
|
| 105 |
|
| 106 |
demo.launch()
|