erwanlc commited on
Commit
8696982
1 Parent(s): e899a1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -8,6 +8,7 @@ tt_generator = pipeline("text2text-generation", model=model_checkpoint)
8
  def generate_text(ingredients):
9
  result = tt_generator(ingredients, min_length=20, max_length=1024, do_sample=True, temperature=1.0, top_p=1.0)
10
  result = result[0]["generated_text"]
 
11
  all_matches = re.findall(r"([A-z][.])", result)
12
  for matches in all_matches:
13
  result = result.replace(matches, f"{matches}\n")
@@ -19,14 +20,17 @@ def generate_text(ingredients):
19
  result[-1] = result[-1].replace(matches, f"\n{matches}")
20
  result = [item.strip() for item in result]
21
  result[-1] = f"\nIngredients:\n{result[-1]}"
 
22
  result = "\n".join(result)
 
 
23
  return result
24
 
25
  title = "Create original cocktails based on your ingredients"
26
  description = "Finetuned T5 on cocktails recipe. Write your ingredients separated by a comma to generate a cocktail. This work was inspired by Chef Transformer (https://huggingface.co/spaces/flax-community/chef-transformer)."
27
  examples = [
28
  ["rum,apricot liqueur,lime juice,sugar syrup"],
29
- ["gin,honey,basil,soda water"]
30
  ]
31
 
32
  output_text = gr.outputs.Textbox()
 
8
  def generate_text(ingredients):
9
  result = tt_generator(ingredients, min_length=20, max_length=1024, do_sample=True, temperature=1.0, top_p=1.0)
10
  result = result[0]["generated_text"]
11
+ result_temp = result
12
  all_matches = re.findall(r"([A-z][.])", result)
13
  for matches in all_matches:
14
  result = result.replace(matches, f"{matches}\n")
 
20
  result[-1] = result[-1].replace(matches, f"\n{matches}")
21
  result = [item.strip() for item in result]
22
  result[-1] = f"\nIngredients:\n{result[-1]}"
23
+ result[-1] = re.sub(" (?=[A-Z])", "\n", result[-1])
24
  result = "\n".join(result)
25
+ result = re.sub("(?<=[0-9].)\n(?=[0-9])", "", result)
26
+ print(result_temp)
27
  return result
28
 
29
  title = "Create original cocktails based on your ingredients"
30
  description = "Finetuned T5 on cocktails recipe. Write your ingredients separated by a comma to generate a cocktail. This work was inspired by Chef Transformer (https://huggingface.co/spaces/flax-community/chef-transformer)."
31
  examples = [
32
  ["rum,apricot liqueur,lime juice,sugar syrup"],
33
+ ["gin,honey,basil leaves,soda water"]
34
  ]
35
 
36
  output_text = gr.outputs.Textbox()