Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,7 @@ def generate_cocktail(mood, sweetness, sour, savory, bitter, flavor_association,
|
|
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"
|
34 |
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"
|
35 |
-
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:[ingredients]\nInstruction:[instruction]\nNotes:[notes]"
|
36 |
prompt = instruction + user_prompt + output_format
|
37 |
|
38 |
messages=[
|
@@ -50,14 +50,14 @@ def generate_cocktail(mood, sweetness, sour, savory, bitter, flavor_association,
|
|
50 |
return f'<p style="color: white; font-size: 20px;">{str(e)}</p>'
|
51 |
|
52 |
def extract_info(output_text):
|
53 |
-
pattern = r"Cocktail Name:(.*?)
|
54 |
match = re.search(pattern, output_text, re.DOTALL)
|
55 |
if match:
|
56 |
-
name = match.group(1)
|
57 |
-
quote = match.group(2)
|
58 |
-
ingredients = match.group(3)
|
59 |
-
instruction = match.group(4)
|
60 |
-
notes = match.group(5)
|
61 |
return name, quote, ingredients, instruction, notes
|
62 |
else:
|
63 |
return None
|
@@ -65,10 +65,10 @@ def extract_info(output_text):
|
|
65 |
def format_cocktail_output(name, quote, ingredients, instruction, notes):
|
66 |
# Construct the HTML output
|
67 |
html_output = f'''
|
68 |
-
<div style="text-align: center; font-family: '
|
69 |
-
<h1 style="font-size:
|
70 |
-
<p style="font-size:
|
71 |
-
<p style="font-size:
|
72 |
<strong>Ingredients:</strong> {ingredients}<br>
|
73 |
<strong>Instruction:</strong> {instruction}<br>
|
74 |
<strong>Notes:</strong> {notes}<br>
|
|
|
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"
|
34 |
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"
|
35 |
+
output_format = "Please strictly follow this output format:\n\nCocktail Name:[name]\n\nQuote:[one sentence quote related to the cocktail and the mood description]\n\nIngredients:[ingredients one at a line]\n\nInstruction:[instruction]\n\nNotes:[notes]"
|
36 |
prompt = instruction + user_prompt + output_format
|
37 |
|
38 |
messages=[
|
|
|
50 |
return f'<p style="color: white; font-size: 20px;">{str(e)}</p>'
|
51 |
|
52 |
def extract_info(output_text):
|
53 |
+
pattern = r"Cocktail Name:(.*?)Quote:(.*?)Ingredients:(.*?)Instruction:(.*?)Notes:(.*?)$"
|
54 |
match = re.search(pattern, output_text, re.DOTALL)
|
55 |
if match:
|
56 |
+
name = match.group(1)
|
57 |
+
quote = match.group(2)
|
58 |
+
ingredients = match.group(3)
|
59 |
+
instruction = match.group(4)
|
60 |
+
notes = match.group(5)
|
61 |
return name, quote, ingredients, instruction, notes
|
62 |
else:
|
63 |
return None
|
|
|
65 |
def format_cocktail_output(name, quote, ingredients, instruction, notes):
|
66 |
# Construct the HTML output
|
67 |
html_output = f'''
|
68 |
+
<div style="text-align: center; font-family: 'monospace'; color: #FFFFFF;">
|
69 |
+
<h1 style="font-size: 40px;">{name}</h1>
|
70 |
+
<p style="font-size: 30px; margin-top: -10px; font-style: italic;">{quote}</p>
|
71 |
+
<p style="font-size: 18px;">
|
72 |
<strong>Ingredients:</strong> {ingredients}<br>
|
73 |
<strong>Instruction:</strong> {instruction}<br>
|
74 |
<strong>Notes:</strong> {notes}<br>
|