Update app.py
Browse files
app.py
CHANGED
@@ -40,10 +40,22 @@ pipe = pipeline(
|
|
40 |
|
41 |
def respond(user_input):
|
42 |
if not user_input.strip():
|
43 |
-
return "请输入植物相关的问题
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
# Gradio 界面
|
49 |
gr.Interface(
|
|
|
40 |
|
41 |
def respond(user_input):
|
42 |
if not user_input.strip():
|
43 |
+
return "请输入植物相关的问题 😊"
|
44 |
+
|
45 |
+
# 使用 prompt 模板,但提示模型不要复述用户提问
|
46 |
+
prompt = (
|
47 |
+
f"请直接给出建议并推荐相关植物文献或资料,不要复读用户的问题。\n\n"
|
48 |
+
f"问题:{user_input}\n回答:"
|
49 |
+
)
|
50 |
+
result = pipe(prompt, return_full_text=False) # 使用 pipeline 的参数,若支持的话
|
51 |
+
output = result[0]["generated_text"]
|
52 |
+
|
53 |
+
# 如果 pipeline 不支持 return_full_text,把以下注释放开:
|
54 |
+
# prompt_tokens = tokenizer(prompt, return_tensors="pt").input_ids.shape[1]
|
55 |
+
# full = tokenizer.decode(model.generate(...)[0], skip_special_tokens=True)
|
56 |
+
# output = full[prompt_tokens:].strip()
|
57 |
+
|
58 |
+
return output.strip()
|
59 |
|
60 |
# Gradio 界面
|
61 |
gr.Interface(
|