tywei08 commited on
Commit
f1c382f
·
verified ·
1 Parent(s): 157adeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -14
app.py CHANGED
@@ -102,13 +102,11 @@ with gr.Blocks(css=css_styles) as demo:
102
  with gr.Row():
103
  output_recipe = gr.HTML(label="Your Cocktail Recipe")
104
 
105
- with gr.Row():
106
- play_button = gr.Button("Play Music", visible=False, elem_classes=["generate-button"], scale=1) # Initially not visible
107
- background_music = gr.Audio(label="Background Music", autoplay=True, visible=False, scale=4) # Initially not visible
108
 
109
  with gr.Row():
110
  save_pdf_button = gr.Button("Download Recipe", visible=False)
111
- pdf_link = gr.File(label="Download PDF", visible=False)
112
 
113
  def on_generate_click(*args):
114
  recipe, show_play_button, show_save_button = generate_cocktail(*args)
@@ -117,20 +115,13 @@ with gr.Blocks(css=css_styles) as demo:
117
  def save_as_pdf(html_content):
118
  # Define path for temporary HTML and PDF files
119
  html_path = "output_recipe.html"
120
- pdf_path = "output_recipe.pdf"
121
 
122
  # Write the HTML content to a temporary HTML file
123
  with open(html_path, 'w') as f:
124
  f.write(html_content)
125
-
126
- # Convert HTML to PDF
127
- pdfkit.from_file(html_path, pdf_path)
128
-
129
- # Provide a link for the generated PDF
130
- return pdf_path
131
 
132
  def reset():
133
- return "", 0, 0, 0, 0, [], [], 10, "", "", "", gr.update(visible=False), gr.update(visible=False)
134
 
135
  generate_button.click(
136
  fn=on_generate_click,
@@ -140,9 +131,9 @@ with gr.Blocks(css=css_styles) as demo:
140
 
141
  play_button.click(fn=play_music, inputs=[], outputs=[background_music, background_music])
142
 
143
- save_pdf_button.click(fn=save_as_pdf, inputs=output_recipe, outputs=pdf_link)
144
 
145
- 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])
146
 
147
  if __name__ == "__main__":
148
  demo.launch(#enable_queue=False,
 
102
  with gr.Row():
103
  output_recipe = gr.HTML(label="Your Cocktail Recipe")
104
 
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("Download Recipe", visible=False)
 
110
 
111
  def on_generate_click(*args):
112
  recipe, show_play_button, show_save_button = generate_cocktail(*args)
 
115
  def save_as_pdf(html_content):
116
  # Define path for temporary HTML and PDF files
117
  html_path = "output_recipe.html"
 
118
 
119
  # Write the HTML content to a temporary HTML file
120
  with open(html_path, 'w') as f:
121
  f.write(html_content)
 
 
 
 
 
 
122
 
123
  def reset():
124
+ return "", 0, 0, 0, 0, [], [], 10, "", "", "", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
125
 
126
  generate_button.click(
127
  fn=on_generate_click,
 
131
 
132
  play_button.click(fn=play_music, inputs=[], outputs=[background_music, background_music])
133
 
134
+ save_pdf_button.click(fn=save_as_pdf, inputs=output_recipe, outputs=[]])
135
 
136
+ 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, save_pdf_button])
137
 
138
  if __name__ == "__main__":
139
  demo.launch(#enable_queue=False,