vam commited on
Commit
c0a0cd2
1 Parent(s): 6ebae13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -19
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
- 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(
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.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()
 
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()