updated prompt
Browse files- app.py +22 -18
- chroma/28c81268-af8d-4e89-9744-aee894bcbde6/data_level0.bin +0 -3
- chroma/28c81268-af8d-4e89-9744-aee894bcbde6/header.bin +0 -3
- chroma/28c81268-af8d-4e89-9744-aee894bcbde6/index_metadata.pickle +0 -3
- chroma/28c81268-af8d-4e89-9744-aee894bcbde6/length.bin +0 -3
- chroma/28c81268-af8d-4e89-9744-aee894bcbde6/link_lists.bin +0 -3
- chroma/8b53584a-0ad0-4736-8a94-cfa8d70be50f/header.bin +0 -3
- chroma/c2db2536-5ceb-4ce6-b43c-7b5a8994dc6a/data_level0.bin +0 -3
- chroma/c2db2536-5ceb-4ce6-b43c-7b5a8994dc6a/index_metadata.pickle +0 -3
- chroma/c2db2536-5ceb-4ce6-b43c-7b5a8994dc6a/length.bin +0 -3
- chroma/c2db2536-5ceb-4ce6-b43c-7b5a8994dc6a/link_lists.bin +0 -3
- chroma/chroma.sqlite3 +2 -2
- chroma/{8b53584a-0ad0-4736-8a94-cfa8d70be50f → db67d0e6-bc9f-4536-a3d5-3b23e19e0212}/data_level0.bin +1 -1
- chroma/{c2db2536-5ceb-4ce6-b43c-7b5a8994dc6a → db67d0e6-bc9f-4536-a3d5-3b23e19e0212}/header.bin +0 -0
- chroma/{8b53584a-0ad0-4736-8a94-cfa8d70be50f → db67d0e6-bc9f-4536-a3d5-3b23e19e0212}/index_metadata.pickle +1 -1
- chroma/{8b53584a-0ad0-4736-8a94-cfa8d70be50f → db67d0e6-bc9f-4536-a3d5-3b23e19e0212}/length.bin +1 -1
- chroma/{8b53584a-0ad0-4736-8a94-cfa8d70be50f → db67d0e6-bc9f-4536-a3d5-3b23e19e0212}/link_lists.bin +1 -1
app.py
CHANGED
@@ -2,7 +2,6 @@
|
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
from langchain.vectorstores import Chroma
|
4 |
from langchain.embeddings import HuggingFaceEmbeddings
|
5 |
-
from peft import AutoPeftModelForCausalLM
|
6 |
|
7 |
import gradio as gr
|
8 |
import hanzidentifier
|
@@ -18,14 +17,15 @@ current_path=str(pathlib.Path(__file__).parent.resolve())
|
|
18 |
llm_model_name="Qwen/Qwen1.5-0.5B-Chat"
|
19 |
|
20 |
#pipe = pipeline("text2text-generation", model=model)
|
21 |
-
#model = AutoModelForCausalLM.from_pretrained(
|
22 |
-
# llm_model_name
|
23 |
-
#)
|
24 |
-
|
25 |
model = AutoModelForCausalLM.from_pretrained(
|
26 |
"ytyeung/Qwen1.5-0.5B-Chat-SFT-riddles",
|
27 |
)
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
tokenizer = AutoTokenizer.from_pretrained(llm_model_name)
|
30 |
|
31 |
# %%
|
@@ -72,16 +72,20 @@ threshold = 0.6
|
|
72 |
def answer(input_text,context=None):
|
73 |
if context:
|
74 |
tips = "提示:\n"
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
81 |
else:
|
82 |
tips=""
|
83 |
|
84 |
-
prompt = f"{input_text}\n{tips}\n谜底是什么?"
|
85 |
prompt = prompt.strip()
|
86 |
|
87 |
print(f"===\n{prompt}")
|
@@ -120,7 +124,7 @@ def helper_rag(text):
|
|
120 |
context = []
|
121 |
for doc in docs_out:
|
122 |
if doc[1] > threshold:
|
123 |
-
context.append((
|
124 |
|
125 |
return context
|
126 |
|
@@ -132,7 +136,7 @@ def helper_text(text_input,radio=None):
|
|
132 |
text_input = chinese_converter.to_simplified(text_input)
|
133 |
chinese_type = "traditional"
|
134 |
|
135 |
-
text_input = re.sub(r'hint',"猜",text_input,flags=re.I)
|
136 |
|
137 |
#if not any(c in text_input for c in ["猜", "打"]):
|
138 |
# warning = "请给一个提示,提示格式,例子:猜一水果,打一字。"
|
@@ -140,10 +144,9 @@ def helper_text(text_input,radio=None):
|
|
140 |
# warning = chinese_converter.to_traditional(warning)
|
141 |
# return warning
|
142 |
|
143 |
-
text=f"""猜谜语:\n谜面:{text_input}
|
144 |
-
"""
|
145 |
|
146 |
-
context = helper_rag(
|
147 |
|
148 |
output = answer(text,context=context)
|
149 |
|
@@ -248,6 +251,7 @@ def translate_text(text_input,text_output):
|
|
248 |
|
249 |
text_input = translate(f"{text_input}")
|
250 |
text_output = translate(f"{text_output}")
|
|
|
251 |
return text_input,text_output
|
252 |
|
253 |
|
@@ -266,7 +270,7 @@ with gr.Blocks() as demo:
|
|
266 |
["小家伙穿黄袍,花丛中把房造。飞到西来飞到东,人人夸他爱劳动。(猜一动物)"],
|
267 |
["一物生来身穿三百多件衣,每天脱一件,年底剩张皮。(猜一物品)"],
|
268 |
["A thousand threads, a million strands. Reaching the water, vanishing all at once. (Hint: natural phenomenon)"],
|
269 |
-
["
|
270 |
]
|
271 |
radio = gr.Radio(
|
272 |
["简体中文","繁體中文", "English"],show_label=False,value="简体中文"
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
from langchain.vectorstores import Chroma
|
4 |
from langchain.embeddings import HuggingFaceEmbeddings
|
|
|
5 |
|
6 |
import gradio as gr
|
7 |
import hanzidentifier
|
|
|
17 |
llm_model_name="Qwen/Qwen1.5-0.5B-Chat"
|
18 |
|
19 |
#pipe = pipeline("text2text-generation", model=model)
|
|
|
|
|
|
|
|
|
20 |
model = AutoModelForCausalLM.from_pretrained(
|
21 |
"ytyeung/Qwen1.5-0.5B-Chat-SFT-riddles",
|
22 |
)
|
23 |
|
24 |
+
#model = AutoPeftModelForCausalLM.from_pretrained(
|
25 |
+
# "Qwen1.5_0.5B_Chat_sft_full/checkpoint-300",
|
26 |
+
# low_cpu_mem_usage=True,
|
27 |
+
#)
|
28 |
+
|
29 |
tokenizer = AutoTokenizer.from_pretrained(llm_model_name)
|
30 |
|
31 |
# %%
|
|
|
72 |
def answer(input_text,context=None):
|
73 |
if context:
|
74 |
tips = "提示:\n"
|
75 |
+
for i, tip in enumerate(context):
|
76 |
+
#if i==0:
|
77 |
+
# tips +="最佳答案\n"
|
78 |
+
#else:
|
79 |
+
# tips +="較差答案\n"
|
80 |
+
tips += f"谜面:{tip[0]} 谜底是:{tip[1]} "
|
81 |
+
tips +="\n"
|
82 |
+
print (f"====\n{input_text}\n{context[0][0]} 谜底是:{context[0][1]} {context[0][2]}")
|
83 |
+
if context[0][2] >=0.9:
|
84 |
+
return f"谜底是:{context[0][1]}"
|
85 |
else:
|
86 |
tips=""
|
87 |
|
88 |
+
prompt = f"{input_text}\n\n{tips}\n\n谜底是什么?"
|
89 |
prompt = prompt.strip()
|
90 |
|
91 |
print(f"===\n{prompt}")
|
|
|
124 |
context = []
|
125 |
for doc in docs_out:
|
126 |
if doc[1] > threshold:
|
127 |
+
context.append((doc[0].page_content, doc[0].metadata['answer'], doc[1]))
|
128 |
|
129 |
return context
|
130 |
|
|
|
136 |
text_input = chinese_converter.to_simplified(text_input)
|
137 |
chinese_type = "traditional"
|
138 |
|
139 |
+
text_input = re.sub(r'hint:',"猜",text_input,flags=re.I)
|
140 |
|
141 |
#if not any(c in text_input for c in ["猜", "打"]):
|
142 |
# warning = "请给一个提示,提示格式,例子:猜一水果,打一字。"
|
|
|
144 |
# warning = chinese_converter.to_traditional(warning)
|
145 |
# return warning
|
146 |
|
147 |
+
text=f"""猜谜语:\n谜面:{text_input}"""
|
|
|
148 |
|
149 |
+
context = helper_rag(text_input)
|
150 |
|
151 |
output = answer(text,context=context)
|
152 |
|
|
|
251 |
|
252 |
text_input = translate(f"{text_input}")
|
253 |
text_output = translate(f"{text_output}")
|
254 |
+
|
255 |
return text_input,text_output
|
256 |
|
257 |
|
|
|
270 |
["小家伙穿黄袍,花丛中把房造。飞到西来飞到东,人人夸他爱劳动。(猜一动物)"],
|
271 |
["一物生来身穿三百多件衣,每天脱一件,年底剩张皮。(猜一物品)"],
|
272 |
["A thousand threads, a million strands. Reaching the water, vanishing all at once. (Hint: natural phenomenon)"],
|
273 |
+
["无底洞(猜一成语)"],
|
274 |
]
|
275 |
radio = gr.Radio(
|
276 |
["简体中文","繁體中文", "English"],show_label=False,value="简体中文"
|
chroma/28c81268-af8d-4e89-9744-aee894bcbde6/data_level0.bin
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:0067068c3258f065668e2ad17382df3424f1c001807139881c2dc1691772ac7b
|
3 |
-
size 28908000
|
|
|
|
|
|
|
|
chroma/28c81268-af8d-4e89-9744-aee894bcbde6/header.bin
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:4b630aa796b842f9cb3af4a5f7cbc9fd3fc793047cec78a183ac3eaa83d68497
|
3 |
-
size 100
|
|
|
|
|
|
|
|
chroma/28c81268-af8d-4e89-9744-aee894bcbde6/index_metadata.pickle
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:e1f937c780ce5ab483dc40c3bf8d8408b3fa3d1bf03b5d20488b0d5b8a906fde
|
3 |
-
size 520085
|
|
|
|
|
|
|
|
chroma/28c81268-af8d-4e89-9744-aee894bcbde6/length.bin
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:3a76c43e6fc007afd7f87d90b5a60a482449450491f8b307c5617b83471cf7a7
|
3 |
-
size 36000
|
|
|
|
|
|
|
|
chroma/28c81268-af8d-4e89-9744-aee894bcbde6/link_lists.bin
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:dcde28a793504ace57c738a180d964a0c8ed59bf30194cdde6f16484f267ba06
|
3 |
-
size 80540
|
|
|
|
|
|
|
|
chroma/8b53584a-0ad0-4736-8a94-cfa8d70be50f/header.bin
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:2ffd87324d19f8f6366a4be4dccc22a83a50ca6837d1327fb660dc4b4e25d140
|
3 |
-
size 100
|
|
|
|
|
|
|
|
chroma/c2db2536-5ceb-4ce6-b43c-7b5a8994dc6a/data_level0.bin
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:0fab3b1442c2e9319c9406cb2db197e9b806a2d4122f8c3575c62d4a0fff1dc5
|
3 |
-
size 3212000
|
|
|
|
|
|
|
|
chroma/c2db2536-5ceb-4ce6-b43c-7b5a8994dc6a/index_metadata.pickle
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:ca24af71d714f0248ef6b2057c614abc943d509f5289bfdaf8d41d3f4d38d22c
|
3 |
-
size 55974
|
|
|
|
|
|
|
|
chroma/c2db2536-5ceb-4ce6-b43c-7b5a8994dc6a/length.bin
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:9814e6d812bbb532273fec5061e2a38f55f8cab0dbe292ff0ba8d230076943ce
|
3 |
-
size 4000
|
|
|
|
|
|
|
|
chroma/c2db2536-5ceb-4ce6-b43c-7b5a8994dc6a/link_lists.bin
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:2f5dc8c4171f8df8a126112a3ebe4e91ccb0895344eff083d43ad767f6effc54
|
3 |
-
size 8148
|
|
|
|
|
|
|
|
chroma/chroma.sqlite3
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5b44b6dd7c8ba23f9faa645c2562ec8b601e93f915588d07876518ac0a686614
|
3 |
+
size 7327744
|
chroma/{8b53584a-0ad0-4736-8a94-cfa8d70be50f → db67d0e6-bc9f-4536-a3d5-3b23e19e0212}/data_level0.bin
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
size 3212000
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b6b26a194dc2620543256c04ccea396ecd8de5787096f7d87d9a9474e9480754
|
3 |
size 3212000
|
chroma/{c2db2536-5ceb-4ce6-b43c-7b5a8994dc6a → db67d0e6-bc9f-4536-a3d5-3b23e19e0212}/header.bin
RENAMED
File without changes
|
chroma/{8b53584a-0ad0-4736-8a94-cfa8d70be50f → db67d0e6-bc9f-4536-a3d5-3b23e19e0212}/index_metadata.pickle
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
size 55974
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:84ebb46c8fd7958ede9a01c261de4f9f85f1020cf32b8ef2afeca67e0b0c62d0
|
3 |
size 55974
|
chroma/{8b53584a-0ad0-4736-8a94-cfa8d70be50f → db67d0e6-bc9f-4536-a3d5-3b23e19e0212}/length.bin
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
size 4000
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:45569e91b592cc6a9fce4ee6a878eb041638b21d09934f0b7158eda3aa83ad89
|
3 |
size 4000
|
chroma/{8b53584a-0ad0-4736-8a94-cfa8d70be50f → db67d0e6-bc9f-4536-a3d5-3b23e19e0212}/link_lists.bin
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
size 8148
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:421b1cc5ed6bbb1c3f7433d3afd18fcc96e7b0b4d670b4f374b599eec28bd8f2
|
3 |
size 8148
|