llk010502 commited on
Commit
3739f4a
1 Parent(s): 3343c56

changes on app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- from transformers import AutoModel, AutoTokenizer, AutoModelForCausalLM
3
  from peft import PeftModel
4
  import re
5
  import os
@@ -12,6 +12,7 @@ import math
12
  from datetime import date
13
  from datetime import date, datetime, timedelta
14
 
 
15
  access_token = os.environ["TOKEN"]
16
 
17
  # load model
@@ -22,7 +23,9 @@ tokenizer = AutoTokenizer.from_pretrained(model, token = access_token, trust_rem
22
  tokenizer.pad_token = tokenizer.eos_token
23
  tokenizer.padding_side = "right"
24
 
25
- model = AutoModelForCausalLM.from_pretrained(model, trust_remote_code=True, token = access_token, device_map="auto", load_in_8bit=True, offload_folder="offload/")
 
 
26
  model = PeftModel.from_pretrained(model, peft_model, offload_folder="offload/")
27
 
28
  model = model.eval()
@@ -366,7 +369,10 @@ def get_all_prompts_online(symbol, with_basics=True, max_news_perweek = 3, weeks
366
  new_system_prompt = SYSTEM_PROMPT.replace(':\n...', ':\n预测涨跌幅:...\n总结分析:...')
367
  prompt = B_INST + B_SYS + new_system_prompt + E_SYS + info + f"\n\n基于在{end_date}之前的所有信息,让我们首先分析{stock}的积极发展和潜在担忧。请简洁地陈述,分别提出2-4个最重要的因素。大部分所提及的因素应该从公司的相关新闻中推断出来。" \
368
  f"接下来请预测{symbol}下周({period})的股票涨跌幅,并提供一个总结分析来支持你的预测。" + E_INST
369
-
 
 
 
370
  return info, prompt
371
 
372
 
@@ -382,7 +388,9 @@ def ask(symbol, weeks_before):
382
 
383
  res = model.generate(
384
  **inputs,
385
- use_cache=True
 
 
386
  )
387
  output = tokenizer.decode(res[0], skip_special_tokens=True)
388
  output_cur = re.sub(r'.*\[/INST\]\s*', '', output, flags=re.DOTALL)
 
1
  import gradio as gr
2
+ from transformers import AutoModel, AutoTokenizer, AutoModelForCausalLM, TextStreamer
3
  from peft import PeftModel
4
  import re
5
  import os
 
12
  from datetime import date
13
  from datetime import date, datetime, timedelta
14
 
15
+
16
  access_token = os.environ["TOKEN"]
17
 
18
  # load model
 
23
  tokenizer.pad_token = tokenizer.eos_token
24
  tokenizer.padding_side = "right"
25
 
26
+ streamer = TextStreamer(tokenizer)
27
+
28
+ model = AutoModelForCausalLM.from_pretrained(model, trust_remote_code=True, token = access_token, device_map="cuda", load_in_8bit=True, offload_folder="offload/")
29
  model = PeftModel.from_pretrained(model, peft_model, offload_folder="offload/")
30
 
31
  model = model.eval()
 
369
  new_system_prompt = SYSTEM_PROMPT.replace(':\n...', ':\n预测涨跌幅:...\n总结分析:...')
370
  prompt = B_INST + B_SYS + new_system_prompt + E_SYS + info + f"\n\n基于在{end_date}之前的所有信息,让我们首先分析{stock}的积极发展和潜在担忧。请简洁地陈述,分别提出2-4个最重要的因素。大部分所提及的因素应该从公司的相关新闻中推断出来。" \
371
  f"接下来请预测{symbol}下周({period})的股票涨跌幅,并提供一个总结分析来支持你的预测。" + E_INST
372
+
373
+ del prev_rows
374
+ del data
375
+
376
  return info, prompt
377
 
378
 
 
388
 
389
  res = model.generate(
390
  **inputs,
391
+ use_cache=True,
392
+ max_length = 4096,
393
+ streamer=streamer
394
  )
395
  output = tokenizer.decode(res[0], skip_special_tokens=True)
396
  output_cur = re.sub(r'.*\[/INST\]\s*', '', output, flags=re.DOTALL)