Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# pipe = pipeline(task="text2text-generation", model="Jumpy-pku/t5-dish-name-recognition")
|
5 |
+
# pipe_aux = pipeline(task="text2text-generation", model="Jumpy-pku/t5-dish-name-recognition-auxiliary")
|
6 |
+
pipe = pipeline(task="text2text-generation", model="model/t5-name-cot")
|
7 |
+
pipe_aux = pipeline(task="text2text-generation", model="model/t5-component")
|
8 |
+
|
9 |
+
def predict(input_text):
|
10 |
+
|
11 |
+
verbs = pipe_aux(f"“{input_text}”这个菜谱的主要操作是什么?", max_length=20, num_return_sequences=1)[0]["generated_text"]
|
12 |
+
flavs = pipe_aux(f"“{input_text}”这个菜谱的主要风味是什么?", max_length=20, num_return_sequences=1)[0]["generated_text"]
|
13 |
+
ings = pipe_aux(f"“{input_text}”这个菜谱的主要食材是什么?", max_length=20, num_return_sequences=1)[0]["generated_text"]
|
14 |
+
|
15 |
+
comp_prompt = ""
|
16 |
+
if verbs:
|
17 |
+
comp_prompt += f"这个菜谱的主要操作是{verbs},"
|
18 |
+
if flavs:
|
19 |
+
comp_prompt += f"这个菜谱的主要风味是{flavs},"
|
20 |
+
if ings:
|
21 |
+
comp_prompt += f"这个菜谱的主要食材是{ings},"
|
22 |
+
comp_prompt += "这个菜谱的菜名是什么?"
|
23 |
+
|
24 |
+
return pipe(f"“{input_text}”{comp_prompt}", max_length=20, num_return_sequences=1)[0]["generated_text"]
|
25 |
+
|
26 |
+
|
27 |
+
demo = gr.Interface(fn=predict, inputs="text", outputs="text", title="菜名生成", description="输入菜谱步骤,生成菜名。")
|
28 |
+
demo.launch()
|