Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -28,6 +28,31 @@ def create_assistant_json(uploaded_file, assistant_name, assistant_message):
|
|
28 |
|
29 |
return assistant.id
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
def generate_cocktail(mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests):
|
32 |
client = openai.OpenAI(api_key=os.environ["API_TOKEN"])
|
33 |
instruction = "Please provide a cocktail recipe given the mood and preference of the user.\n\n"
|
@@ -45,11 +70,11 @@ def generate_cocktail(mood, sweetness, sour, savory, bitter, flavor_association,
|
|
45 |
messages=messages,
|
46 |
max_tokens=1024)
|
47 |
name, quote, ingredients, instruction, notes = extract_info(response.choices[0].message.content)
|
48 |
-
|
49 |
-
background_music_component.update(visible=True)
|
50 |
-
return format_cocktail_output(name, quote, ingredients, instruction, notes, play_button,background_music_component)
|
51 |
except Exception as e:
|
52 |
return f'<p style="color: white; font-size: 20px;">{str(e)}</p>'
|
|
|
|
|
53 |
|
54 |
def extract_info(output_text):
|
55 |
pattern = r"Cocktail Name:(.*?)Quote:(.*?)Ingredients:(.*?)Instruction:(.*?)Notes:(.*?)$"
|
@@ -81,9 +106,6 @@ def format_cocktail_output(name, quote, ingredients, instruction, notes):
|
|
81 |
</div>
|
82 |
'''
|
83 |
return html_output
|
84 |
-
|
85 |
-
def play_music():
|
86 |
-
return 'RPReplay_Final1712757356.mp3'
|
87 |
|
88 |
# Creating the Gradio interface
|
89 |
with gr.Blocks(css='''
|
@@ -110,6 +132,7 @@ with gr.Blocks(css='''
|
|
110 |
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
|
111 |
}
|
112 |
''') as demo:
|
|
|
113 |
with gr.Row():
|
114 |
gr.HTML("""
|
115 |
<h2 style='text-align: center; color: white;'>MoodShaker Cocktail Generator</h2>
|
@@ -139,22 +162,32 @@ with gr.Blocks(css='''
|
|
139 |
with gr.Row():
|
140 |
output_recipe = gr.HTML(label="Your Cocktail Recipe")
|
141 |
|
142 |
-
|
143 |
-
background_music_component = gr.Audio(label="Background Music", autoplay=True, visible=False)
|
144 |
|
145 |
-
|
|
|
146 |
# generate_button.click(
|
147 |
# fn=generate_cocktail,
|
148 |
# inputs=[mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests],
|
149 |
-
# outputs=output_recipe
|
150 |
# )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
generate_button.click(
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
156 |
|
157 |
-
play_button.click(fn=play_music, inputs=[], outputs=background_music_component)
|
158 |
|
159 |
|
160 |
# sweetness .range-slider {background: #FAD02E;}
|
|
|
28 |
|
29 |
return assistant.id
|
30 |
|
31 |
+
def play_music():
|
32 |
+
music_path = "RPReplay_Final1712757356.mp3"
|
33 |
+
return music_path, gr.update(visible=True)
|
34 |
+
|
35 |
+
# def generate_cocktail(mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests):
|
36 |
+
# client = openai.OpenAI(api_key=os.environ["API_TOKEN"])
|
37 |
+
# instruction = "Please provide a cocktail recipe given the mood and preference of the user.\n\n"
|
38 |
+
# user_prompt = f"Mood: {mood}\nTaste: Sweetness {sweetness}/10, Sour {sour}/10, Savory {savory}/10, Bitter {bitter}/10\nFlavor Association: {flavor_association}\nDrinking Experience: {drinking_experience}\nLevel of Soberness: {soberness_level}\nAllergies: {allergies}\nAdditional Requests: {additional_requests}\n\nMake sure to avoid all allergic ingredients.\n\n"
|
39 |
+
# output_format = "Please strictly follow this output format:\n\nCocktail Name:[name]\nQuote:[one sentence quote related to the cocktail and the mood description]\nIngredients:[ingredient 1]\n[ingredient 2]\n...\nInstruction:1. [step 1]\n2. [step 2]\n...\nNotes:[notes]"
|
40 |
+
# prompt = instruction + user_prompt + output_format
|
41 |
+
|
42 |
+
# messages=[
|
43 |
+
# {"role": "system", "content": "You are a helpful bartender assistant."},
|
44 |
+
# {"role": "user", "content": prompt}
|
45 |
+
# ]
|
46 |
+
# try:
|
47 |
+
# response = client.chat.completions.create(
|
48 |
+
# model="gpt-4-0125-preview",
|
49 |
+
# messages=messages,
|
50 |
+
# max_tokens=1024)
|
51 |
+
# name, quote, ingredients, instruction, notes = extract_info(response.choices[0].message.content)
|
52 |
+
# return format_cocktail_output(name, quote, ingredients, instruction, notes), "Play background music"
|
53 |
+
# except Exception as e:
|
54 |
+
# return f'<p style="color: white; font-size: 20px;">{str(e)}</p>'
|
55 |
+
|
56 |
def generate_cocktail(mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests):
|
57 |
client = openai.OpenAI(api_key=os.environ["API_TOKEN"])
|
58 |
instruction = "Please provide a cocktail recipe given the mood and preference of the user.\n\n"
|
|
|
70 |
messages=messages,
|
71 |
max_tokens=1024)
|
72 |
name, quote, ingredients, instruction, notes = extract_info(response.choices[0].message.content)
|
73 |
+
return format_cocktail_output(name, quote, ingredients, instruction, notes),True
|
|
|
|
|
74 |
except Exception as e:
|
75 |
return f'<p style="color: white; font-size: 20px;">{str(e)}</p>'
|
76 |
+
|
77 |
+
|
78 |
|
79 |
def extract_info(output_text):
|
80 |
pattern = r"Cocktail Name:(.*?)Quote:(.*?)Ingredients:(.*?)Instruction:(.*?)Notes:(.*?)$"
|
|
|
106 |
</div>
|
107 |
'''
|
108 |
return html_output
|
|
|
|
|
|
|
109 |
|
110 |
# Creating the Gradio interface
|
111 |
with gr.Blocks(css='''
|
|
|
132 |
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
|
133 |
}
|
134 |
''') as demo:
|
135 |
+
|
136 |
with gr.Row():
|
137 |
gr.HTML("""
|
138 |
<h2 style='text-align: center; color: white;'>MoodShaker Cocktail Generator</h2>
|
|
|
162 |
with gr.Row():
|
163 |
output_recipe = gr.HTML(label="Your Cocktail Recipe")
|
164 |
|
165 |
+
output_recipe = gr.HTML(label="Your Cocktail Recipe")
|
|
|
166 |
|
167 |
+
|
168 |
+
#modified
|
169 |
# generate_button.click(
|
170 |
# fn=generate_cocktail,
|
171 |
# inputs=[mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests],
|
172 |
+
# outputs=[output_recipe, play_button]
|
173 |
# )
|
174 |
+
|
175 |
+
play_button = gr.Button("Play Background Music", visible=False) # Initially not visible
|
176 |
+
background_music = gr.Audio(label="Background Music", autoplay=True, visible=False) # Initially not visible
|
177 |
+
|
178 |
+
def on_generate_click(*args):
|
179 |
+
recipe, show_play_button = generate_cocktail(*args)
|
180 |
+
return recipe, gr.update(visible=show_play_button)
|
181 |
+
|
182 |
+
|
183 |
generate_button.click(
|
184 |
+
fn=on_generate_click,
|
185 |
+
inputs=[mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests],
|
186 |
+
outputs=[output_recipe, play_button]
|
187 |
+
)
|
188 |
+
|
189 |
+
play_button.click(fn=play_music, inputs=[], outputs=[background_music, background_music])
|
190 |
|
|
|
191 |
|
192 |
|
193 |
# sweetness .range-slider {background: #FAD02E;}
|