tywei08 commited on
Commit
ba6ed6c
·
verified ·
1 Parent(s): 056db4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -21
app.py CHANGED
@@ -47,9 +47,9 @@ def generate_cocktail(mood, sweetness, sour, savory, bitter, flavor_association,
47
  messages=messages,
48
  max_tokens=1024)
49
  name, quote, ingredients, instruction, notes = extract_info(response.choices[0].message.content)
50
- return format_cocktail_output(name, quote, ingredients, instruction, notes), True, True
51
  except Exception as e:
52
- return f'<p style="color: white; font-size: 20px;">{str(e)}</p>', True, True
53
 
54
  # Extract information from the response generated by OpenAI
55
  def extract_info(output_text):
@@ -85,14 +85,6 @@ def format_cocktail_output(name, quote, ingredients, instruction, notes):
85
  '''
86
  return html_output
87
 
88
- def save_as_png(html_content):
89
- """Converts HTML content to PDF, encodes it in base64, and returns a download link."""
90
- hti = Html2Image()
91
- css = 'body {background: url("https://images.unsplash.com/photo-1514361726087-38371321b5cd?q=80&w=2370&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D");}'
92
-
93
- # screenshot an HTML string (css is optional)
94
- hti.screenshot(html_str=html_content, css_str=css, save_as="CocktailRecipe.png")
95
-
96
 
97
  with open('style.css', 'r') as file:
98
  css_styles = file.read()
@@ -129,22 +121,18 @@ with gr.Blocks(css=css_styles, theme='xiaobaiyuan/theme_brief@>=0.0.2,<0.0.3') a
129
 
130
  play_button = gr.Button("Play Music", visible=False, elem_classes=["generate-button"], scale=1) # Initially not visible
131
  background_music = gr.Audio(label="Background Music", autoplay=True, visible=False, scale=4) # Initially not visible
132
- pdf_download_link = gr.HTML(visible=False) # For displaying the PDF download link
133
-
134
- with gr.Row():
135
- save_png_button = gr.Button("Download Recipe as PNG", visible=False)
136
 
137
  def on_generate_click(*args):
138
- recipe, show_play_button, show_save_button = generate_cocktail(*args)
139
- return recipe, gr.update(visible=show_play_button), gr.update(visible=show_save_button)
140
 
141
  def reset():
142
- return "", 0, 0, 0, 0, [], [], 10, "", "", "", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
143
 
144
  generate_button.click(
145
  fn=on_generate_click,
146
  inputs=[mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests],
147
- outputs=[output_recipe, play_button, save_png_button]
148
  )
149
 
150
  with gr.Row():
@@ -155,10 +143,8 @@ with gr.Blocks(css=css_styles, theme='xiaobaiyuan/theme_brief@>=0.0.2,<0.0.3') a
155
  outputs=[output_recipe, play_button], fn=on_generate_click, elem_id="example-box")
156
 
157
  play_button.click(fn=play_music, inputs=[], outputs=[background_music, background_music])
158
-
159
- save_png_button.click(fn=save_as_png, inputs=[output_recipe], outputs=[pdf_download_link])
160
 
161
- 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_png_button])
162
 
163
  if __name__ == "__main__":
164
  MoodShaker.launch(#enable_queue=False,
 
47
  messages=messages,
48
  max_tokens=1024)
49
  name, quote, ingredients, instruction, notes = extract_info(response.choices[0].message.content)
50
+ return format_cocktail_output(name, quote, ingredients, instruction, notes), True
51
  except Exception as e:
52
+ return f'<p style="color: white; font-size: 20px;">{str(e)}</p>', True
53
 
54
  # Extract information from the response generated by OpenAI
55
  def extract_info(output_text):
 
85
  '''
86
  return html_output
87
 
 
 
 
 
 
 
 
 
88
 
89
  with open('style.css', 'r') as file:
90
  css_styles = file.read()
 
121
 
122
  play_button = gr.Button("Play Music", visible=False, elem_classes=["generate-button"], scale=1) # Initially not visible
123
  background_music = gr.Audio(label="Background Music", autoplay=True, visible=False, scale=4) # Initially not visible
 
 
 
 
124
 
125
  def on_generate_click(*args):
126
+ recipe, show_play_button = generate_cocktail(*args)
127
+ return recipe, gr.update(visible=show_play_button)
128
 
129
  def reset():
130
+ return "", 0, 0, 0, 0, [], [], 10, "", "", "", gr.update(visible=False), gr.update(visible=False)
131
 
132
  generate_button.click(
133
  fn=on_generate_click,
134
  inputs=[mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests],
135
+ outputs=[output_recipe, play_button]
136
  )
137
 
138
  with gr.Row():
 
143
  outputs=[output_recipe, play_button], fn=on_generate_click, elem_id="example-box")
144
 
145
  play_button.click(fn=play_music, inputs=[], outputs=[background_music, background_music])
 
 
146
 
147
+ 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])
148
 
149
  if __name__ == "__main__":
150
  MoodShaker.launch(#enable_queue=False,