benjamin5607 commited on
Commit
aaa6263
ยท
verified ยท
1 Parent(s): 84f6106

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +11 -12
streamlit_app.py CHANGED
@@ -7,7 +7,7 @@ from huggingface_hub import InferenceClient
7
  st.set_page_config(page_title="Pocket Quant", page_icon="๐Ÿ“ˆ", layout="centered")
8
 
9
  st.title("๐Ÿ‡จ๐Ÿ‡ณ Qwen ํˆฌ์ž ์ž๋ฌธ๊ฐ€")
10
- st.caption("AI์˜ ๊ป์งˆ์„ ๊ฐ•์ œ๋กœ ๋ฒ—๊ฒจ์„œ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.")
11
 
12
  # 2. ํ† ํฐ ํ™•์ธ
13
  if "HF_TOKEN" in st.secrets:
@@ -31,14 +31,18 @@ def search_ticker(input_text):
31
  market = res.iloc[0]['Market']
32
  return f"{code}.KS" if market == 'KOSPI' else f"{code}.KQ"
33
 
34
- # --- [ํ•ต์‹ฌ] AI๊ฐ€ ๋ณด๋‚ด๋Š” ์ŠคํŠธ๋ฆผ์—์„œ ์ฝ”๋“œ๋ฐ•์Šค(```) ๊ธฐํ˜ธ๋งŒ ๋ฐœ๋ผ๋‚ด๋Š” ํ•จ์ˆ˜ ---
35
  def parse_stream(stream):
36
  for chunk in stream:
37
- content = chunk.choices[0].delta.content
38
- if content:
39
- # ```markdown, ```, ` ๊ธฐํ˜ธ๋ฅผ ์‚ญ์ œํ•ด๋ฒ„๋ฆผ
40
- cleaned = content.replace("```markdown", "").replace("```", "")
41
- yield cleaned
 
 
 
 
42
 
43
  # 5. ๋ฉ”์ธ UI
44
  user_input = st.text_input("๋ถ„์„ํ•  ์ข…๋ชฉ (์˜ˆ: ์‚ผ์„ฑ์ „์ž, ์นด์นด์˜ค)", "์‚ผ์„ฑ์ „์ž")
@@ -60,7 +64,6 @@ if st.button("๐Ÿš€ AI ๋ถ„์„ ์‹œ์ž‘", use_container_width=True):
60
  start = hist['Close'].iloc[0]
61
  change = ((curr - start) / start) * 100
62
 
63
- # ํ”„๋กฌํ”„ํŠธ: '์ฝ”๋“œ ์“ฐ์ง€ ๋ง๋ผ'๊ณ  ํ•œ๋ฒˆ ๋” ๊ฐ•์กฐ
64
  prompt = f"""
65
  [์ง€์‹œ์‚ฌํ•ญ]
66
  ๋„ˆ๋Š” ์ฃผ์‹ ํˆฌ์ž ์ „๋ฌธ๊ฐ€์•ผ. ์•„๋ž˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๊ณ  ๋ณด๊ณ ์„œ๋ฅผ ์ž‘์„ฑํ•ด.
@@ -79,13 +82,11 @@ if st.button("๐Ÿš€ AI ๋ถ„์„ ์‹œ์ž‘", use_container_width=True):
79
  ## ๐Ÿ“ ์ƒ์„ธ ๋ถ„์„
80
  """
81
 
82
- # ๋ฐ์ดํ„ฐ ์ˆจ๊น€
83
  with st.expander("๐Ÿ”ข ๋ฐ์ดํ„ฐ ์›๋ณธ ๋ณด๊ธฐ"):
84
  st.json(info)
85
 
86
  status.update(label="โœ… ๋ถ„์„ ์™„๋ฃŒ!", state="complete", expanded=False)
87
 
88
- # ๊ฒฐ๊ณผ ํ™”๋ฉด
89
  st.divider()
90
  col1, col2 = st.columns([1, 2])
91
  with col1:
@@ -100,7 +101,6 @@ if st.button("๐Ÿš€ AI ๋ถ„์„ ์‹œ์ž‘", use_container_width=True):
100
  {"role": "user", "content": prompt}
101
  ]
102
 
103
- # AI ํ˜ธ์ถœ
104
  stream = client.chat.completions.create(
105
  model="Qwen/Qwen2.5-72B-Instruct",
106
  messages=messages,
@@ -108,7 +108,6 @@ if st.button("๐Ÿš€ AI ๋ถ„์„ ์‹œ์ž‘", use_container_width=True):
108
  stream=True
109
  )
110
 
111
- # [์—ฌ๊ธฐ!] ์šฐ๋ฆฌ๊ฐ€ ๋งŒ๋“  ํ•„ํ„ฐ ํ•จ์ˆ˜(parse_stream)๋ฅผ ํ†ต๊ณผ์‹œ์ผœ์„œ ์ถœ๋ ฅ
112
  st.write_stream(parse_stream(stream))
113
 
114
  else:
 
7
  st.set_page_config(page_title="Pocket Quant", page_icon="๐Ÿ“ˆ", layout="centered")
8
 
9
  st.title("๐Ÿ‡จ๐Ÿ‡ณ Qwen ํˆฌ์ž ์ž๋ฌธ๊ฐ€")
10
+ st.caption("AI์˜ ๊ป์งˆ์„ ๊ฐ•์ œ๋กœ ๋ฒ—๊ฒจ์„œ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. (์˜ค๋ฅ˜ ์ˆ˜์ •ํŒ)")
11
 
12
  # 2. ํ† ํฐ ํ™•์ธ
13
  if "HF_TOKEN" in st.secrets:
 
31
  market = res.iloc[0]['Market']
32
  return f"{code}.KS" if market == 'KOSPI' else f"{code}.KQ"
33
 
34
+ # --- [์ˆ˜์ •๋จ] ์•ˆ์ „์žฅ์น˜๊ฐ€ ์ถ”๊ฐ€๋œ ํ•„ํ„ฐ ํ•จ์ˆ˜ ---
35
  def parse_stream(stream):
36
  for chunk in stream:
37
+ # ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๊ณ , choices ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋น„์–ด์žˆ์ง€ ์•Š์€์ง€ ํ™•์ธ (์ด๊ฒŒ ์—๋Ÿฌ ํ•ด๊ฒฐ ํ•ต์‹ฌ!)
38
+ if chunk.choices and len(chunk.choices) > 0:
39
+ delta = chunk.choices[0].delta
40
+ # ๋‚ด์šฉ(content)์ด ์žˆ์„ ๋•Œ๋งŒ ์ฒ˜๋ฆฌ
41
+ if hasattr(delta, 'content') and delta.content:
42
+ content = delta.content
43
+ # ๋งˆํฌ๋‹ค์šด ์ฝ”๋“œ ๊ธฐํ˜ธ ์‚ญ์ œ
44
+ cleaned = content.replace("```markdown", "").replace("```", "")
45
+ yield cleaned
46
 
47
  # 5. ๋ฉ”์ธ UI
48
  user_input = st.text_input("๋ถ„์„ํ•  ์ข…๋ชฉ (์˜ˆ: ์‚ผ์„ฑ์ „์ž, ์นด์นด์˜ค)", "์‚ผ์„ฑ์ „์ž")
 
64
  start = hist['Close'].iloc[0]
65
  change = ((curr - start) / start) * 100
66
 
 
67
  prompt = f"""
68
  [์ง€์‹œ์‚ฌํ•ญ]
69
  ๋„ˆ๋Š” ์ฃผ์‹ ํˆฌ์ž ์ „๋ฌธ๊ฐ€์•ผ. ์•„๋ž˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๊ณ  ๋ณด๊ณ ์„œ๋ฅผ ์ž‘์„ฑํ•ด.
 
82
  ## ๐Ÿ“ ์ƒ์„ธ ๋ถ„์„
83
  """
84
 
 
85
  with st.expander("๐Ÿ”ข ๋ฐ์ดํ„ฐ ์›๋ณธ ๋ณด๊ธฐ"):
86
  st.json(info)
87
 
88
  status.update(label="โœ… ๋ถ„์„ ์™„๋ฃŒ!", state="complete", expanded=False)
89
 
 
90
  st.divider()
91
  col1, col2 = st.columns([1, 2])
92
  with col1:
 
101
  {"role": "user", "content": prompt}
102
  ]
103
 
 
104
  stream = client.chat.completions.create(
105
  model="Qwen/Qwen2.5-72B-Instruct",
106
  messages=messages,
 
108
  stream=True
109
  )
110
 
 
111
  st.write_stream(parse_stream(stream))
112
 
113
  else: