tywei08 commited on
Commit
427764a
·
verified ·
1 Parent(s): a4ab90f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -95,20 +95,39 @@ with gr.Blocks(css=css_styles) as demo:
95
  with gr.Row():
96
  allergies = gr.Textbox(label="Allergies", scale=2, elem_classes=["custom-input1"])
97
  additional_requests = gr.Textbox(label="Anything else you would like to address", scale=2, elem_classes=["custom-input2"])
98
- generate_button = gr.Button("Generate Your Cocktail Recipe", scale=0.75, elem_classes=["generate-button"])
99
- clear_button = gr.Button("Clear", scale=0.25)
100
 
101
  with gr.Row():
102
  output_recipe = gr.HTML(label="Your Cocktail Recipe")
103
 
104
  with gr.Row():
105
- play_button = gr.Button("Play Music", visible=False, elem_classes=["generate-button"], scale=4) # Initially not visible
106
- background_music = gr.Audio(label="Background Music", autoplay=True, visible=False) # Initially not visible
 
 
 
 
107
 
108
  def on_generate_click(*args):
109
  recipe, show_play_button = generate_cocktail(*args)
110
  return recipe, gr.update(visible=show_play_button)
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  def reset():
113
  return "", 0, 0, 0, 0, [], [], 10, "", "", "", gr.update(visible=False), gr.update(visible=False)
114
 
@@ -120,6 +139,8 @@ with gr.Blocks(css=css_styles) as demo:
120
 
121
  play_button.click(fn=play_music, inputs=[], outputs=[background_music, background_music])
122
 
 
 
123
  clear_button.click(fn=reset, inputs=[], outputs=[mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests, output_recipe, play_button, background_music])
124
 
125
  if __name__ == "__main__":
 
95
  with gr.Row():
96
  allergies = gr.Textbox(label="Allergies", scale=2, elem_classes=["custom-input1"])
97
  additional_requests = gr.Textbox(label="Anything else you would like to address", scale=2, elem_classes=["custom-input2"])
98
+ generate_button = gr.Button("Generate Your Cocktail Recipe", scale=0.85, elem_classes=["generate-button"])
99
+ clear_button = gr.Button("Clear", scale=0.15)
100
 
101
  with gr.Row():
102
  output_recipe = gr.HTML(label="Your Cocktail Recipe")
103
 
104
  with gr.Row():
105
+ play_button = gr.Button("Play Music", visible=False, elem_classes=["generate-button"], scale=1) # Initially not visible
106
+ background_music = gr.Audio(label="Background Music", autoplay=True, visible=False, scale=4) # Initially not visible
107
+
108
+ with gr.Row():
109
+ save_pdf_button = gr.Button("Save as PDF")
110
+ pdf_link = gr.File(label="Download PDF", visible=False)
111
 
112
  def on_generate_click(*args):
113
  recipe, show_play_button = generate_cocktail(*args)
114
  return recipe, gr.update(visible=show_play_button)
115
 
116
+ def save_as_pdf(html_content):
117
+ # Define path for temporary HTML and PDF files
118
+ html_path = "output_recipe.html"
119
+ pdf_path = "output_recipe.pdf"
120
+
121
+ # Write the HTML content to a temporary HTML file
122
+ with open(html_path, 'w') as f:
123
+ f.write(html_content)
124
+
125
+ # Convert HTML to PDF
126
+ pdfkit.from_file(html_path, pdf_path)
127
+
128
+ # Provide a link for the generated PDF
129
+ return pdf_path
130
+
131
  def reset():
132
  return "", 0, 0, 0, 0, [], [], 10, "", "", "", gr.update(visible=False), gr.update(visible=False)
133
 
 
139
 
140
  play_button.click(fn=play_music, inputs=[], outputs=[background_music, background_music])
141
 
142
+ save_pdf_button.click(fn=save_as_pdf, inputs=output_recipe, outputs=pdf_link)
143
+
144
  clear_button.click(fn=reset, inputs=[], outputs=[mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests, output_recipe, play_button, background_music])
145
 
146
  if __name__ == "__main__":