Barman-T5 / app.py
erwanlc's picture
Update app.py
b8a124d
raw
history blame
1.02 kB
import gradio as gr
from transformers import pipeline
model_checkpoint = "erwanlc/t5-cocktails_recipe-base"
tt_generator = pipeline("text2text-generation", model=model_checkpoint)
def generate_text(ingredients):
result = tt_generator(ingredients, min_length=20, max_length=1024, do_sample=True, temperature=1.0, top_p=1.0)
result = result[0]["generated_text"]
all_matches = re.findall(r"([A-z][.])", result)
for matches in all_matches:
result = result.replace(matches, f"{matches}\n")
result = result.split("\n")
all_matches = re.finditer(r"([0-9]*[.])?[0-9]+ ", result[-1])
all_matches = list(all_matches)
all_matches = set([item.group() for item in all_matches])
for matches in all_matches:
result[-1] = result[-1].replace(matches, f"\n{matches}")
result = [item.strip() for item in result]
result = "\n".join(result)
return result
output_text = gr.outputs.Textbox()
gr.Interface(fn=generate_text, inputs="textbox", outputs=output_text).launch(share=True)