Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -43,10 +43,39 @@ def generate_cocktail(mood, sweetness, sour, savory, bitter, flavor_association,
|
|
43 |
model="gpt-4-0125-preview",
|
44 |
messages=messages,
|
45 |
max_tokens=1024)
|
46 |
-
|
|
|
47 |
except Exception as e:
|
48 |
return f'<p style="color: white; font-size: 20px;">{str(e)}</p>'
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
# Creating the Gradio interface
|
51 |
with gr.Blocks(css='''
|
52 |
.gradio-container {
|
@@ -83,7 +112,7 @@ with gr.Blocks(css='''
|
|
83 |
generate_button = gr.Button("Generate Your Cocktail Recipe")
|
84 |
|
85 |
with gr.Row():
|
86 |
-
output_recipe = gr.
|
87 |
|
88 |
generate_button.click(
|
89 |
fn=generate_cocktail,
|
|
|
43 |
model="gpt-4-0125-preview",
|
44 |
messages=messages,
|
45 |
max_tokens=1024)
|
46 |
+
name, quote, ingredients, instruction, notes = extract_info(response.choices[0].message.content)
|
47 |
+
return format_cocktail_output(name, quote, ingredients, instruction, notes)
|
48 |
except Exception as e:
|
49 |
return f'<p style="color: white; font-size: 20px;">{str(e)}</p>'
|
50 |
|
51 |
+
def extract_info(output_text):
|
52 |
+
pattern = r"Cocktail Name:(.*?)\nQuote:(.*?)\nIngredients:(.*?)\nInstruction:(.*?)\nNotes:(.*?)$"
|
53 |
+
match = re.search(pattern, output_text, re.DOTALL)
|
54 |
+
if match:
|
55 |
+
name = match.group(1).strip()
|
56 |
+
quote = match.group(2).strip()
|
57 |
+
ingredients = match.group(3).strip()
|
58 |
+
instruction = match.group(4).strip()
|
59 |
+
notes = match.group(5).strip()
|
60 |
+
return name, quote, ingredients, instruction, notes
|
61 |
+
else:
|
62 |
+
return None
|
63 |
+
|
64 |
+
def format_cocktail_output(name, quote, ingredients, instruction, notes):
|
65 |
+
# Construct the HTML output
|
66 |
+
html_output = f'''
|
67 |
+
<div style="text-align: center; font-family: 'fantasy'; color: #fff;">
|
68 |
+
<h1 style="font-size: 24px;">{name}</h1>
|
69 |
+
<p style="font-size: 18px; margin-top: -10px; font-style: italic;">"{quote}"</p>
|
70 |
+
<p style="font-size: 16px;">
|
71 |
+
<strong>Ingredients:</strong> {ingredients}<br>
|
72 |
+
<strong>Instruction:</strong> {instruction}<br>
|
73 |
+
<strong>Notes:</strong> {notes}<br>
|
74 |
+
</p>
|
75 |
+
</div>
|
76 |
+
'''
|
77 |
+
return html_output
|
78 |
+
|
79 |
# Creating the Gradio interface
|
80 |
with gr.Blocks(css='''
|
81 |
.gradio-container {
|
|
|
112 |
generate_button = gr.Button("Generate Your Cocktail Recipe")
|
113 |
|
114 |
with gr.Row():
|
115 |
+
output_recipe = gr.HTML(label="Your Cocktail Recipe")
|
116 |
|
117 |
generate_button.click(
|
118 |
fn=generate_cocktail,
|