tywei08 commited on
Commit
c5cf242
·
verified ·
1 Parent(s): 44bc7e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
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:(.*?)\nQuote:(.*?)\nIngredients:(.*?)\nInstruction:(.*?)\nNotes:(.*?)$"
54
  match = re.search(pattern, output_text, re.DOTALL)
55
  if match:
56
- name = match.group(1).strip()
57
- quote = match.group(2).strip()
58
- ingredients = match.group(3).strip()
59
- instruction = match.group(4).strip()
60
- notes = match.group(5).strip()
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: 'fantasy'; color: #fff;">
69
- <h1 style="font-size: 24px;">{name}</h1>
70
- <p style="font-size: 18px; margin-top: -10px; font-style: italic;">"{quote}"</p>
71
- <p style="font-size: 16px;">
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>