Spaces:
Runtime error
Runtime error
Commit
·
babf8f8
1
Parent(s):
3a06b0d
add csv
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import transformers
|
|
4 |
from transformers import pipeline
|
5 |
from transformers import LlamaTokenizer, LlamaForCausalLM
|
6 |
import time
|
7 |
-
|
8 |
#https://huggingface.co/shibing624/chinese-alpaca-plus-7b-hf
|
9 |
#https://huggingface.co/ziqingyang/chinese-alpaca-2-7b
|
10 |
#https://huggingface.co/minlik/chinese-alpaca-plus-7b-merged
|
@@ -37,42 +37,58 @@ with open('alpaca_output.csv', 'a', newline='',encoding = "utf-8") as csvfile:
|
|
37 |
writer = csv.writer(csvfile)
|
38 |
writer.writerow(["stockname",'prompt','answer','time'])
|
39 |
if user_input:
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
# top_k=40,
|
76 |
-
|
77 |
-
# ).cuda()
|
78 |
-
# output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
|
|
4 |
from transformers import pipeline
|
5 |
from transformers import LlamaTokenizer, LlamaForCausalLM
|
6 |
import time
|
7 |
+
import csv
|
8 |
#https://huggingface.co/shibing624/chinese-alpaca-plus-7b-hf
|
9 |
#https://huggingface.co/ziqingyang/chinese-alpaca-2-7b
|
10 |
#https://huggingface.co/minlik/chinese-alpaca-plus-7b-merged
|
|
|
37 |
writer = csv.writer(csvfile)
|
38 |
writer.writerow(["stockname",'prompt','answer','time'])
|
39 |
if user_input:
|
40 |
+
if user_input[0] = "模":
|
41 |
+
stockname = user_input[1:4]
|
42 |
+
analysis = user_input[4:]
|
43 |
+
|
44 |
+
text = f"""請以肯定和專業的語氣,一步一步的思考並回答以下關於{stockname}的問題,避免空洞的答覆:
|
45 |
+
- 請回答關於{stockname}的問題,請總結給予的資料以及資料解釋,並整合出金融上的洞見。\n
|
46 |
+
- 請不要生成任何資料沒有提供的數據,即便你已知道。\n
|
47 |
+
- 請假裝這些資料都是你預先知道的知識。因此,請不要提到「根據資料」、「基於上述資料」等回答
|
48 |
+
- 請不要說「好的、我明白了、根據我的要求、以下是我的答案」等贅詞,請輸出分析結果即可\n
|
49 |
+
- 請寫300字到500字之間,若合適,可以進行分類、列點
|
50 |
+
資料:{stockname}{analysis}
|
51 |
+
|
52 |
+
請特別注意,分析結果包含籌碼面、基本面以及技術面,請針對這三個面向進行回答,並且特別注意個別符合幾項和不符合幾項。籌碼面、技術面和基本面滿分十分,總計滿分為30分。
|
53 |
+
三個面向中,符合5項以上代表該面項表現好,反之是該面項表現差。
|
54 |
+
"""
|
55 |
|
56 |
+
prompt = generate_prompt(text)
|
57 |
+
start = time.time()
|
58 |
+
sequences = pipeline(
|
59 |
+
prompt,
|
60 |
+
do_sample=True,
|
61 |
+
top_k=40,
|
62 |
+
num_return_sequences=1,
|
63 |
+
eos_token_id=tokenizer.eos_token_id,
|
64 |
+
max_length=200,
|
65 |
+
)
|
66 |
+
end = time.time()
|
67 |
+
for seq in sequences:
|
68 |
+
st.write(f"Result: {seq}") #seq['generated_text']
|
69 |
+
st.write(f"time: {(end-start):.2f}")
|
70 |
|
71 |
+
# input_ids = tokenizer.encode(prompt, return_tensors='pt').to('cuda')
|
72 |
+
# with torch.no_grad():
|
73 |
+
# output_ids = model.generate(
|
74 |
+
# input_ids=input_ids,
|
75 |
+
# max_new_tokens=2048,
|
76 |
+
# top_k=40,
|
77 |
+
|
78 |
+
# ).cuda()
|
79 |
+
# output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
80 |
+
else:
|
81 |
+
prompt = generate_prompt(user_input)
|
82 |
+
start = time.time()
|
83 |
+
sequences = pipeline(
|
84 |
+
prompt,
|
85 |
+
do_sample=True,
|
86 |
+
top_k=40,
|
87 |
+
num_return_sequences=1,
|
88 |
+
eos_token_id=tokenizer.eos_token_id,
|
89 |
+
max_length=200,
|
90 |
+
)
|
91 |
+
end = time.time()
|
92 |
+
for seq in sequences:
|
93 |
+
st.write(f"Result: {seq}") #seq['generated_text']
|
94 |
+
st.write(f"time: {(end-start):.2f}")
|
|
|
|
|
|
|
|