Spaces:
Runtime error
Runtime error
Commit ·
f4348d4
1
Parent(s): 0fdebe8
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,9 @@ 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
|
|
@@ -21,7 +24,7 @@ tokenizer = LlamaTokenizer.from_pretrained('shibing624/chinese-alpaca-plus-7b-hf
|
|
| 21 |
pipeline = pipeline(
|
| 22 |
"text-generation",
|
| 23 |
model="shibing624/chinese-alpaca-plus-7b-hf",
|
| 24 |
-
torch_dtype=torch.
|
| 25 |
device_map="auto",
|
| 26 |
)
|
| 27 |
|
|
@@ -35,7 +38,7 @@ user_input = st.text_input("")
|
|
| 35 |
|
| 36 |
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 |
if user_input[0] == ".":
|
| 41 |
stockname = user_input[1:4]
|
|
@@ -67,6 +70,7 @@ with open('alpaca_output.csv', 'a', newline='',encoding = "utf-8") as csvfile:
|
|
| 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():
|
|
@@ -92,3 +96,4 @@ with open('alpaca_output.csv', 'a', newline='',encoding = "utf-8") as csvfile:
|
|
| 92 |
for seq in sequences:
|
| 93 |
st.write(f"Result: {seq}") #seq['generated_text']
|
| 94 |
st.write(f"time: {(end-start):.2f}")
|
|
|
|
|
|
| 5 |
from transformers import LlamaTokenizer, LlamaForCausalLM
|
| 6 |
import time
|
| 7 |
import csv
|
| 8 |
+
import locale
|
| 9 |
+
locale.getpreferredencoding = lambda: "UTF-8"
|
| 10 |
+
|
| 11 |
#https://huggingface.co/shibing624/chinese-alpaca-plus-7b-hf
|
| 12 |
#https://huggingface.co/ziqingyang/chinese-alpaca-2-7b
|
| 13 |
#https://huggingface.co/minlik/chinese-alpaca-plus-7b-merged
|
|
|
|
| 24 |
pipeline = pipeline(
|
| 25 |
"text-generation",
|
| 26 |
model="shibing624/chinese-alpaca-plus-7b-hf",
|
| 27 |
+
torch_dtype=torch.float32,
|
| 28 |
device_map="auto",
|
| 29 |
)
|
| 30 |
|
|
|
|
| 38 |
|
| 39 |
with open('alpaca_output.csv', 'a', newline='',encoding = "utf-8") as csvfile:
|
| 40 |
writer = csv.writer(csvfile)
|
| 41 |
+
# writer.writerow(["stockname",'prompt','answer','time'])
|
| 42 |
if user_input:
|
| 43 |
if user_input[0] == ".":
|
| 44 |
stockname = user_input[1:4]
|
|
|
|
| 70 |
for seq in sequences:
|
| 71 |
st.write(f"Result: {seq}") #seq['generated_text']
|
| 72 |
st.write(f"time: {(end-start):.2f}")
|
| 73 |
+
writer.writerow([stockname,text,sequences,f"time: {(end-start):.2f}"])
|
| 74 |
|
| 75 |
# input_ids = tokenizer.encode(prompt, return_tensors='pt').to('cuda')
|
| 76 |
# with torch.no_grad():
|
|
|
|
| 96 |
for seq in sequences:
|
| 97 |
st.write(f"Result: {seq}") #seq['generated_text']
|
| 98 |
st.write(f"time: {(end-start):.2f}")
|
| 99 |
+
writer.writerow(["無",user_input,sequences,f"time: {(end-start):.2f}"])
|