Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,19 @@ tt_generator = pipeline("text2text-generation", model=model_checkpoint)
|
|
6 |
|
7 |
def generate_text(ingredients):
|
8 |
result = tt_generator(ingredients, min_length=20, max_length=1024, do_sample=True, temperature=1.0, top_p=1.0)
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
output_text = gr.outputs.Textbox()
|
12 |
gr.Interface(fn=generate_text, inputs="textbox", outputs=output_text).launch(share=True)
|
|
|
6 |
|
7 |
def generate_text(ingredients):
|
8 |
result = tt_generator(ingredients, min_length=20, max_length=1024, do_sample=True, temperature=1.0, top_p=1.0)
|
9 |
+
result = result[0]["generated_text"]
|
10 |
+
all_matches = re.findall(r"([A-z][.])", result)
|
11 |
+
for matches in all_matches:
|
12 |
+
result = result.replace(matches, f"{matches}\n")
|
13 |
+
result = result.split("\n")
|
14 |
+
all_matches = re.finditer(r"([0-9]*[.])?[0-9]+ ", result[-1])
|
15 |
+
all_matches = list(all_matches)
|
16 |
+
all_matches = set([item.group() for item in all_matches])
|
17 |
+
for matches in all_matches:
|
18 |
+
result[-1] = result[-1].replace(matches, f"\n{matches}")
|
19 |
+
result = [item.strip() for item in result]
|
20 |
+
result = "\n".join(result)
|
21 |
+
return result
|
22 |
|
23 |
output_text = gr.outputs.Textbox()
|
24 |
gr.Interface(fn=generate_text, inputs="textbox", outputs=output_text).launch(share=True)
|