Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import json
|
|
4 |
import re
|
5 |
from datetime import datetime
|
6 |
import openai
|
|
|
7 |
|
8 |
# Function to play background music
|
9 |
def play_music():
|
@@ -30,7 +31,7 @@ def generate_cocktail(mood, sweetness, sour, savory, bitter, flavor_association,
|
|
30 |
messages=messages,
|
31 |
max_tokens=1024)
|
32 |
name, quote, ingredients, instruction, notes = extract_info(response.choices[0].message.content)
|
33 |
-
return format_cocktail_output(name, quote, ingredients, instruction, notes), True
|
34 |
except Exception as e:
|
35 |
return f'<p style="color: white; font-size: 20px;">{str(e)}</p>'
|
36 |
|
@@ -93,10 +94,10 @@ with gr.Blocks(css=css_styles) as demo:
|
|
93 |
soberness_level = gr.Slider(label="Level of Soberness", minimum=0, maximum=10, value=10, elem_id="slider-soberness_level", elem_classes=["slider-soberness_level"])
|
94 |
|
95 |
with gr.Row():
|
96 |
-
allergies = gr.Textbox(label="Allergies", scale=
|
97 |
-
additional_requests = gr.Textbox(label="Anything else you would like to address", scale=
|
98 |
-
generate_button = gr.Button("Generate Your Cocktail Recipe", scale=
|
99 |
-
clear_button = gr.Button("Clear", scale=
|
100 |
|
101 |
with gr.Row():
|
102 |
output_recipe = gr.HTML(label="Your Cocktail Recipe")
|
@@ -106,12 +107,12 @@ with gr.Blocks(css=css_styles) as demo:
|
|
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("
|
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
|
@@ -134,7 +135,7 @@ with gr.Blocks(css=css_styles) as demo:
|
|
134 |
generate_button.click(
|
135 |
fn=on_generate_click,
|
136 |
inputs=[mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests],
|
137 |
-
outputs=[output_recipe, play_button]
|
138 |
)
|
139 |
|
140 |
play_button.click(fn=play_music, inputs=[], outputs=[background_music, background_music])
|
|
|
4 |
import re
|
5 |
from datetime import datetime
|
6 |
import openai
|
7 |
+
import pdfkit
|
8 |
|
9 |
# Function to play background music
|
10 |
def play_music():
|
|
|
31 |
messages=messages,
|
32 |
max_tokens=1024)
|
33 |
name, quote, ingredients, instruction, notes = extract_info(response.choices[0].message.content)
|
34 |
+
return format_cocktail_output(name, quote, ingredients, instruction, notes), True, True
|
35 |
except Exception as e:
|
36 |
return f'<p style="color: white; font-size: 20px;">{str(e)}</p>'
|
37 |
|
|
|
94 |
soberness_level = gr.Slider(label="Level of Soberness", minimum=0, maximum=10, value=10, elem_id="slider-soberness_level", elem_classes=["slider-soberness_level"])
|
95 |
|
96 |
with gr.Row():
|
97 |
+
allergies = gr.Textbox(label="Allergies", scale=6, elem_classes=["custom-input1"])
|
98 |
+
additional_requests = gr.Textbox(label="Anything else you would like to address", scale=6, elem_classes=["custom-input2"])
|
99 |
+
generate_button = gr.Button("Generate Your Cocktail Recipe", scale=3, elem_classes=["generate-button"])
|
100 |
+
clear_button = gr.Button("Clear", scale=1)
|
101 |
|
102 |
with gr.Row():
|
103 |
output_recipe = gr.HTML(label="Your Cocktail Recipe")
|
|
|
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)
|
115 |
+
return recipe, gr.update(visible=show_play_button), gr.update(visible=show_save_button)
|
116 |
|
117 |
def save_as_pdf(html_content):
|
118 |
# Define path for temporary HTML and PDF files
|
|
|
135 |
generate_button.click(
|
136 |
fn=on_generate_click,
|
137 |
inputs=[mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests],
|
138 |
+
outputs=[output_recipe, play_button, save_pdf_button]
|
139 |
)
|
140 |
|
141 |
play_button.click(fn=play_music, inputs=[], outputs=[background_music, background_music])
|