Spaces:
Sleeping
Sleeping
github-actions[bot] commited on
Commit Β·
e589290
1
Parent(s): a572e7a
sync from df72c1c
Browse files- README.md +2 -2
- app.py +245 -131
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -4,9 +4,9 @@ emoji: π
|
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: "
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
license: mit
|
| 11 |
-
short_description: DART + EDGAR disclosure analysis
|
| 12 |
---
|
|
|
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: "6.10.0"
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
license: mit
|
| 11 |
+
short_description: DART + EDGAR disclosure analysis
|
| 12 |
---
|
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
| 4 |
|
| 5 |
import gc
|
| 6 |
import os
|
|
|
|
| 7 |
import threading
|
| 8 |
from collections import OrderedDict
|
| 9 |
|
|
@@ -20,6 +21,12 @@ _HAS_AI = bool(os.environ.get("OPENAI_API_KEY"))
|
|
| 20 |
if _HAS_AI:
|
| 21 |
dartlab.llm.configure(provider="openai", api_key=os.environ["OPENAI_API_KEY"])
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# ββ μ νΈ ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 25 |
|
|
@@ -61,28 +68,62 @@ def _warmup():
|
|
| 61 |
threading.Thread(target=_warmup, daemon=True).start()
|
| 62 |
|
| 63 |
|
| 64 |
-
# ββ νΈλ€λ¬:
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
def
|
| 68 |
-
"""μ’
λͺ©
|
| 69 |
-
if not
|
| 70 |
-
return
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
"""κΈ°μ
κ°μ λ‘λ β (κΈ°λ³Έμ 보 markdown, topics 리μ€νΈ, μ¬λ¬΄ DataFrame)."""
|
| 80 |
-
if not code or not code.strip():
|
| 81 |
-
return "μ’
λͺ©μ½λλ₯Ό μ
λ ₯νμΈμ.", gr.update(choices=[]), None
|
| 82 |
try:
|
| 83 |
c = _getCompany(code)
|
| 84 |
except Exception as e:
|
| 85 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
# κΈ°λ³Έμ 보
|
| 88 |
info = f"## {c.corpName} ({c.stockCode})\n"
|
|
@@ -104,7 +145,12 @@ def handleLoadCompany(code: str):
|
|
| 104 |
except Exception:
|
| 105 |
pass
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
|
| 110 |
def handleFinance(code: str, sheet: str):
|
|
@@ -116,7 +162,7 @@ def handleFinance(code: str, sheet: str):
|
|
| 116 |
except Exception:
|
| 117 |
return None
|
| 118 |
|
| 119 |
-
lookup = {"
|
| 120 |
attr = lookup.get(sheet, "IS")
|
| 121 |
try:
|
| 122 |
result = getattr(c, attr, None)
|
|
@@ -125,9 +171,6 @@ def handleFinance(code: str, sheet: str):
|
|
| 125 |
return None
|
| 126 |
|
| 127 |
|
| 128 |
-
# ββ νΈλ€λ¬: Sections ββββββββββββββββββββββββββββββββββ
|
| 129 |
-
|
| 130 |
-
|
| 131 |
def handleShow(code: str, topic: str):
|
| 132 |
"""sections show β DataFrame λλ Markdown."""
|
| 133 |
if not code or not topic:
|
|
@@ -153,7 +196,10 @@ def handleChat(message: str, history: list, code: str):
|
|
| 153 |
if not _HAS_AI:
|
| 154 |
history = history + [
|
| 155 |
{"role": "user", "content": message},
|
| 156 |
-
{
|
|
|
|
|
|
|
|
|
|
| 157 |
]
|
| 158 |
return history, ""
|
| 159 |
|
|
@@ -161,16 +207,12 @@ def handleChat(message: str, history: list, code: str):
|
|
| 161 |
if not stockCode:
|
| 162 |
history = history + [
|
| 163 |
{"role": "user", "content": message},
|
| 164 |
-
{"role": "assistant", "content": "λ¨Όμ
|
| 165 |
]
|
| 166 |
return history, ""
|
| 167 |
|
| 168 |
-
# ask() νΈμΆ β raw=Trueλ‘ Generator λ°μμ μ€νΈλ¦¬λ°
|
| 169 |
try:
|
| 170 |
-
if stockCode
|
| 171 |
-
query = f"{stockCode} {message}"
|
| 172 |
-
else:
|
| 173 |
-
query = message
|
| 174 |
answer = dartlab.ask(query, stream=False, raw=False)
|
| 175 |
except Exception as e:
|
| 176 |
answer = f"λΆμ μ€ν¨: {e}"
|
|
@@ -185,119 +227,191 @@ def handleChat(message: str, history: list, code: str):
|
|
| 185 |
# ββ UI ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 186 |
|
| 187 |
_CSS = """
|
| 188 |
-
|
| 189 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
"""
|
| 191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
with gr.Blocks(
|
| 193 |
-
title="DartLab β
|
| 194 |
-
theme=
|
| 195 |
css=_CSS,
|
| 196 |
) as demo:
|
| 197 |
-
gr.Markdown("# DartLab", elem_classes="main-title")
|
| 198 |
-
gr.Markdown(
|
| 199 |
-
"DART μ μ곡μ + EDGAR β μ’
λͺ©μ½λ νλλ‘ κΈ°μ
λΆμ",
|
| 200 |
-
elem_classes="subtitle",
|
| 201 |
-
)
|
| 202 |
|
| 203 |
-
#
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
with gr.Tab("Search"):
|
| 209 |
-
with gr.Row():
|
| 210 |
-
searchInput = gr.Textbox(
|
| 211 |
-
label="μ’
λͺ© κ²μ",
|
| 212 |
-
placeholder="μΌμ±μ μ, AAPL, 005930 ...",
|
| 213 |
-
scale=4,
|
| 214 |
-
)
|
| 215 |
-
searchBtn = gr.Button("κ²μ", scale=1, variant="primary")
|
| 216 |
-
searchResult = gr.DataFrame(label="κ²μ κ²°κ³Ό", interactive=False)
|
| 217 |
-
|
| 218 |
-
with gr.Row():
|
| 219 |
-
selectedCode = gr.Textbox(
|
| 220 |
-
label="μ’
λͺ©μ½λ μ
λ ₯ ν λΆμ",
|
| 221 |
-
placeholder="005930",
|
| 222 |
-
scale=4,
|
| 223 |
-
)
|
| 224 |
-
loadBtn = gr.Button("λΆμνκΈ°", scale=1, variant="primary")
|
| 225 |
-
|
| 226 |
-
searchBtn.click(handleSearch, inputs=searchInput, outputs=searchResult)
|
| 227 |
-
searchInput.submit(handleSearch, inputs=searchInput, outputs=searchResult)
|
| 228 |
-
|
| 229 |
-
# ββ Tab 2: κΈ°μ
+ μ¬λ¬΄ ββ
|
| 230 |
-
with gr.Tab("Company"):
|
| 231 |
-
companyInfo = gr.Markdown("μ’
λͺ©μ½λλ₯Ό μ
λ ₯νκ³ 'λΆμνκΈ°'λ₯Ό ν΄λ¦νμΈμ.")
|
| 232 |
-
|
| 233 |
-
with gr.Row():
|
| 234 |
-
sheetSelect = gr.Dropdown(
|
| 235 |
-
choices=["IS", "BS", "CF", "ratios"],
|
| 236 |
-
value="IS",
|
| 237 |
-
label="μ¬λ¬΄μ ν",
|
| 238 |
-
scale=1,
|
| 239 |
-
)
|
| 240 |
-
financeTable = gr.DataFrame(label="μ¬λ¬΄μ ν", interactive=False)
|
| 241 |
-
|
| 242 |
-
sheetSelect.change(
|
| 243 |
-
handleFinance,
|
| 244 |
-
inputs=[codeState, sheetSelect],
|
| 245 |
-
outputs=financeTable,
|
| 246 |
-
)
|
| 247 |
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
)
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
outputs=[sectionTable, sectionText],
|
| 263 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
"Variables and secretsμμ `OPENAI_API_KEY`λ₯Ό μ€μ νμΈμ."
|
| 271 |
-
)
|
| 272 |
-
chatbot = gr.Chatbot(label="AI λΆμ", type="messages", height=500)
|
| 273 |
-
with gr.Row():
|
| 274 |
-
chatInput = gr.Textbox(
|
| 275 |
-
label="μ§λ¬Έ",
|
| 276 |
-
placeholder="μ¬λ¬΄κ±΄μ μ± λΆμν΄μ€, λ°°λΉ μ΄μ μ§ν μ°Ύμμ€ ...",
|
| 277 |
-
scale=5,
|
| 278 |
-
)
|
| 279 |
-
chatBtn = gr.Button("μ μ‘", scale=1, variant="primary")
|
| 280 |
-
|
| 281 |
-
chatBtn.click(
|
| 282 |
-
handleChat,
|
| 283 |
-
inputs=[chatInput, chatbot, codeState],
|
| 284 |
-
outputs=[chatbot, chatInput],
|
| 285 |
-
)
|
| 286 |
-
chatInput.submit(
|
| 287 |
-
handleChat,
|
| 288 |
-
inputs=[chatInput, chatbot, codeState],
|
| 289 |
-
outputs=[chatbot, chatInput],
|
| 290 |
-
)
|
| 291 |
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
outputs=codeState,
|
| 297 |
-
).then(
|
| 298 |
-
handleLoadCompany,
|
| 299 |
-
inputs=selectedCode,
|
| 300 |
-
outputs=[companyInfo, topicSelect, financeTable],
|
| 301 |
)
|
| 302 |
|
| 303 |
|
|
|
|
| 4 |
|
| 5 |
import gc
|
| 6 |
import os
|
| 7 |
+
import re
|
| 8 |
import threading
|
| 9 |
from collections import OrderedDict
|
| 10 |
|
|
|
|
| 21 |
if _HAS_AI:
|
| 22 |
dartlab.llm.configure(provider="openai", api_key=os.environ["OPENAI_API_KEY"])
|
| 23 |
|
| 24 |
+
_LOGO_URL = "https://raw.githubusercontent.com/eddmpython/dartlab/master/.github/assets/logo.png"
|
| 25 |
+
_BLOG_URL = "https://eddmpython.github.io/dartlab/blog/dartlab-easy-start/"
|
| 26 |
+
_DOCS_URL = "https://eddmpython.github.io/dartlab/docs/getting-started/quickstart"
|
| 27 |
+
_COLAB_URL = "https://colab.research.google.com/github/eddmpython/dartlab/blob/master/notebooks/showcase/01_quickstart.ipynb"
|
| 28 |
+
_REPO_URL = "https://github.com/eddmpython/dartlab"
|
| 29 |
+
|
| 30 |
|
| 31 |
# ββ μ νΈ ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 32 |
|
|
|
|
| 68 |
threading.Thread(target=_warmup, daemon=True).start()
|
| 69 |
|
| 70 |
|
| 71 |
+
# ββ νΈλ€λ¬: ν΅ν© λΆμ ββββββββββββββββββββββββββββββββ
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def handleAnalyze(query: str):
|
| 75 |
+
"""μ’
λͺ©μ½λ λλ νμ¬λͺ
β κΈ°μ
μ 보 + μ¬λ¬΄μ ν + topics."""
|
| 76 |
+
if not query or not query.strip():
|
| 77 |
+
return (
|
| 78 |
+
"μ’
λͺ©μ½λ λλ νμ¬λͺ
μ μ
λ ₯νμΈμ.",
|
| 79 |
+
"",
|
| 80 |
+
None,
|
| 81 |
+
gr.update(choices=[], value=None),
|
| 82 |
+
None,
|
| 83 |
+
"",
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
query = query.strip()
|
| 87 |
+
|
| 88 |
+
# μ’
λͺ©μ½λ νλ³: 6μ리 μ«μ λλ μλ¬Έ ν°μ»€
|
| 89 |
+
if re.match(r"^\d{6}$", query) or re.match(r"^[A-Z]{1,5}$", query):
|
| 90 |
+
code = query
|
| 91 |
+
else:
|
| 92 |
+
# κ²μ λ¨Όμ
|
| 93 |
+
try:
|
| 94 |
+
results = dartlab.search(query)
|
| 95 |
+
if results is None or len(results) == 0:
|
| 96 |
+
return (
|
| 97 |
+
f"'{query}' κ²μ κ²°κ³Όκ° μμ΅λλ€. μ’
λͺ©μ½λ(μ: 005930)λ ν°μ»€(μ: AAPL)λ₯Ό μ§μ μ
λ ₯ν΄λ³΄μΈμ.",
|
| 98 |
+
"",
|
| 99 |
+
None,
|
| 100 |
+
gr.update(choices=[], value=None),
|
| 101 |
+
None,
|
| 102 |
+
"",
|
| 103 |
+
)
|
| 104 |
+
code = str(results[0, "stockCode"])
|
| 105 |
+
except Exception as e:
|
| 106 |
+
return (
|
| 107 |
+
f"κ²μ μ€ν¨: {e}",
|
| 108 |
+
"",
|
| 109 |
+
None,
|
| 110 |
+
gr.update(choices=[], value=None),
|
| 111 |
+
None,
|
| 112 |
+
"",
|
| 113 |
+
)
|
| 114 |
|
| 115 |
+
# Company λ‘λ
|
|
|
|
|
|
|
|
|
|
| 116 |
try:
|
| 117 |
c = _getCompany(code)
|
| 118 |
except Exception as e:
|
| 119 |
+
return (
|
| 120 |
+
f"κΈ°μ
λ‘λ μ€ν¨: {e}",
|
| 121 |
+
"",
|
| 122 |
+
None,
|
| 123 |
+
gr.update(choices=[], value=None),
|
| 124 |
+
None,
|
| 125 |
+
"",
|
| 126 |
+
)
|
| 127 |
|
| 128 |
# κΈ°λ³Έμ 보
|
| 129 |
info = f"## {c.corpName} ({c.stockCode})\n"
|
|
|
|
| 145 |
except Exception:
|
| 146 |
pass
|
| 147 |
|
| 148 |
+
topicUpdate = gr.update(
|
| 149 |
+
choices=topics,
|
| 150 |
+
value=topics[0] if topics else None,
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
return info, code, finance, topicUpdate, None, ""
|
| 154 |
|
| 155 |
|
| 156 |
def handleFinance(code: str, sheet: str):
|
|
|
|
| 162 |
except Exception:
|
| 163 |
return None
|
| 164 |
|
| 165 |
+
lookup = {"IS": "IS", "BS": "BS", "CF": "CF", "ratios": "ratios"}
|
| 166 |
attr = lookup.get(sheet, "IS")
|
| 167 |
try:
|
| 168 |
result = getattr(c, attr, None)
|
|
|
|
| 171 |
return None
|
| 172 |
|
| 173 |
|
|
|
|
|
|
|
|
|
|
| 174 |
def handleShow(code: str, topic: str):
|
| 175 |
"""sections show β DataFrame λλ Markdown."""
|
| 176 |
if not code or not topic:
|
|
|
|
| 196 |
if not _HAS_AI:
|
| 197 |
history = history + [
|
| 198 |
{"role": "user", "content": message},
|
| 199 |
+
{
|
| 200 |
+
"role": "assistant",
|
| 201 |
+
"content": "OPENAI_API_KEYκ° μ€μ λμ§ μμμ΅λλ€.\n\nHuggingFace Spaces Settings β Variables and secretsμμ μ€μ νμΈμ.",
|
| 202 |
+
},
|
| 203 |
]
|
| 204 |
return history, ""
|
| 205 |
|
|
|
|
| 207 |
if not stockCode:
|
| 208 |
history = history + [
|
| 209 |
{"role": "user", "content": message},
|
| 210 |
+
{"role": "assistant", "content": "λ¨Όμ μλ¨μμ μ’
λͺ©μ λΆμνμΈμ."},
|
| 211 |
]
|
| 212 |
return history, ""
|
| 213 |
|
|
|
|
| 214 |
try:
|
| 215 |
+
query = f"{stockCode} {message}" if stockCode else message
|
|
|
|
|
|
|
|
|
|
| 216 |
answer = dartlab.ask(query, stream=False, raw=False)
|
| 217 |
except Exception as e:
|
| 218 |
answer = f"λΆμ μ€ν¨: {e}"
|
|
|
|
| 227 |
# ββ UI ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 228 |
|
| 229 |
_CSS = """
|
| 230 |
+
/* ββ dartlab λΈλλ© ββ */
|
| 231 |
+
.gradio-container {
|
| 232 |
+
background: #0a0d16 !important;
|
| 233 |
+
max-width: 960px !important;
|
| 234 |
+
}
|
| 235 |
+
.main-header {
|
| 236 |
+
text-align: center;
|
| 237 |
+
padding: 1.5rem 0 0.5rem;
|
| 238 |
+
}
|
| 239 |
+
.main-header img {
|
| 240 |
+
display: inline-block;
|
| 241 |
+
border-radius: 50%;
|
| 242 |
+
box-shadow: 0 0 32px rgba(234,70,71,0.25);
|
| 243 |
+
}
|
| 244 |
+
.main-header h1 {
|
| 245 |
+
color: #ea4647 !important;
|
| 246 |
+
font-size: 2.2rem !important;
|
| 247 |
+
margin: 0.5rem 0 0.2rem !important;
|
| 248 |
+
font-weight: 800 !important;
|
| 249 |
+
}
|
| 250 |
+
.main-header .tagline {
|
| 251 |
+
color: #94a3b8;
|
| 252 |
+
font-size: 1.05rem;
|
| 253 |
+
margin: 0;
|
| 254 |
+
}
|
| 255 |
+
.section-label {
|
| 256 |
+
color: #ea4647 !important;
|
| 257 |
+
font-weight: 700 !important;
|
| 258 |
+
font-size: 1.1rem !important;
|
| 259 |
+
margin: 1rem 0 0.3rem !important;
|
| 260 |
+
border-bottom: 1px solid #1e2433;
|
| 261 |
+
padding-bottom: 0.3rem;
|
| 262 |
+
}
|
| 263 |
+
.footer-links {
|
| 264 |
+
text-align: center;
|
| 265 |
+
padding: 1.5rem 0 0.5rem;
|
| 266 |
+
color: #64748b;
|
| 267 |
+
font-size: 0.9rem;
|
| 268 |
+
}
|
| 269 |
+
.footer-links a {
|
| 270 |
+
color: #94a3b8 !important;
|
| 271 |
+
text-decoration: none;
|
| 272 |
+
margin: 0 0.5rem;
|
| 273 |
+
}
|
| 274 |
+
.footer-links a:hover {
|
| 275 |
+
color: #ea4647 !important;
|
| 276 |
+
}
|
| 277 |
"""
|
| 278 |
|
| 279 |
+
_THEME = gr.themes.Base(
|
| 280 |
+
primary_hue=gr.themes.Color(
|
| 281 |
+
c50="#fef2f2", c100="#fee2e2", c200="#fecaca", c300="#fca5a5",
|
| 282 |
+
c400="#f87171", c500="#ea4647", c600="#dc2626", c700="#c83232",
|
| 283 |
+
c800="#991b1b", c900="#7f1d1d", c950="#450a0a",
|
| 284 |
+
),
|
| 285 |
+
neutral_hue=gr.themes.Color(
|
| 286 |
+
c50="#f8fafc", c100="#f1f5f9", c200="#e2e8f0", c300="#cbd5e1",
|
| 287 |
+
c400="#94a3b8", c500="#64748b", c600="#475569", c700="#334155",
|
| 288 |
+
c800="#1e293b", c900="#0f172a", c950="#0a0d16",
|
| 289 |
+
),
|
| 290 |
+
font=("system-ui", "-apple-system", "sans-serif"),
|
| 291 |
+
).set(
|
| 292 |
+
body_background_fill="#0a0d16",
|
| 293 |
+
body_text_color="#f1f5f9",
|
| 294 |
+
block_background_fill="#0f1219",
|
| 295 |
+
block_border_color="#1e2433",
|
| 296 |
+
input_background_fill="#1a1f2b",
|
| 297 |
+
button_primary_background_fill="#ea4647",
|
| 298 |
+
button_primary_text_color="#ffffff",
|
| 299 |
+
button_secondary_background_fill="#1a1f2b",
|
| 300 |
+
button_secondary_text_color="#f1f5f9",
|
| 301 |
+
button_secondary_border_color="#1e2433",
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
+
|
| 305 |
with gr.Blocks(
|
| 306 |
+
title="DartLab β μ’
λͺ©μ½λ νλλ‘ κΈ°μ
λΆμ",
|
| 307 |
+
theme=_THEME,
|
| 308 |
css=_CSS,
|
| 309 |
) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
|
| 311 |
+
# ββ ν€λ ββ
|
| 312 |
+
gr.HTML(f"""
|
| 313 |
+
<div class="main-header">
|
| 314 |
+
<img src="{_LOGO_URL}" width="100" height="100" alt="DartLab">
|
| 315 |
+
<h1>DartLab</h1>
|
| 316 |
+
<p class="tagline">μ’
λͺ©μ½λ νλ. κΈ°μ
μ μ 체 μ΄μΌκΈ°.</p>
|
| 317 |
+
</div>
|
| 318 |
+
""")
|
| 319 |
|
| 320 |
+
# ββ 곡μ state ββ
|
| 321 |
+
codeState = gr.State("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
+
# ββ ν΅ν© μ
λ ₯ ββ
|
| 324 |
+
with gr.Row():
|
| 325 |
+
queryInput = gr.Textbox(
|
| 326 |
+
label="μ’
λͺ©μ½λ λλ νμ¬λͺ
",
|
| 327 |
+
placeholder="μΌμ±μ μ, 005930, AAPL ...",
|
| 328 |
+
scale=4,
|
| 329 |
+
)
|
| 330 |
+
analyzeBtn = gr.Button("λΆμνκΈ°", scale=1, variant="primary", size="lg")
|
| 331 |
+
|
| 332 |
+
# ββ κΈ°μ
μ 보 ββ
|
| 333 |
+
companyInfo = gr.Markdown("μ’
λͺ©μ½λλ₯Ό μ
λ ₯νκ³ **λΆμνκΈ°**λ₯Ό ν΄λ¦νμΈμ.")
|
| 334 |
+
|
| 335 |
+
# ββ μ¬λ¬΄μ ν ββ
|
| 336 |
+
gr.Markdown("### μ¬λ¬΄μ ν", elem_classes="section-label")
|
| 337 |
+
with gr.Row():
|
| 338 |
+
sheetSelect = gr.Dropdown(
|
| 339 |
+
choices=["IS", "BS", "CF", "ratios"],
|
| 340 |
+
value="IS",
|
| 341 |
+
label="μνΈ",
|
| 342 |
+
scale=1,
|
| 343 |
+
)
|
| 344 |
+
financeTable = gr.DataFrame(label="μ¬λ¬΄μ ν", interactive=False)
|
| 345 |
+
|
| 346 |
+
# ββ Sections ββ
|
| 347 |
+
gr.Markdown("### Sections β topic Γ period μνν", elem_classes="section-label")
|
| 348 |
+
topicSelect = gr.Dropdown(
|
| 349 |
+
choices=[],
|
| 350 |
+
label="Topic",
|
| 351 |
+
interactive=True,
|
| 352 |
+
)
|
| 353 |
+
sectionTable = gr.DataFrame(label="Section λ°μ΄ν°", interactive=False)
|
| 354 |
+
sectionText = gr.Markdown("")
|
| 355 |
+
|
| 356 |
+
# ββ AI Chat (μ ν) ββ
|
| 357 |
+
with gr.Accordion("AI λΆμ (OpenAI API νμ)", open=False):
|
| 358 |
+
if not _HAS_AI:
|
| 359 |
+
gr.Markdown(
|
| 360 |
+
"**AI λΆμμ μ¬μ©νλ €λ©΄** HuggingFace Spaces Settings β "
|
| 361 |
+
"Variables and secretsμμ `OPENAI_API_KEY`λ₯Ό μ€μ νμΈμ."
|
| 362 |
)
|
| 363 |
+
chatbot = gr.Chatbot(label="AI λΆμ", type="messages", height=400)
|
| 364 |
+
with gr.Row():
|
| 365 |
+
chatInput = gr.Textbox(
|
| 366 |
+
label="μ§λ¬Έ",
|
| 367 |
+
placeholder="μ¬λ¬΄κ±΄μ μ± λΆμν΄μ€, λ°°λΉ μ΄μ μ§ν μ°Ύμμ€ ...",
|
| 368 |
+
scale=5,
|
|
|
|
| 369 |
)
|
| 370 |
+
chatBtn = gr.Button("μ μ‘", scale=1, variant="primary")
|
| 371 |
+
|
| 372 |
+
chatBtn.click(
|
| 373 |
+
handleChat,
|
| 374 |
+
inputs=[chatInput, chatbot, codeState],
|
| 375 |
+
outputs=[chatbot, chatInput],
|
| 376 |
+
)
|
| 377 |
+
chatInput.submit(
|
| 378 |
+
handleChat,
|
| 379 |
+
inputs=[chatInput, chatbot, codeState],
|
| 380 |
+
outputs=[chatbot, chatInput],
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
# ββ νΈν° ββ
|
| 384 |
+
gr.HTML(f"""
|
| 385 |
+
<div class="footer-links">
|
| 386 |
+
<a href="{_BLOG_URL}">π μ€μΉ κ°μ΄λ</a> Β·
|
| 387 |
+
<a href="{_DOCS_URL}">π 곡μ λ¬Έμ</a> Β·
|
| 388 |
+
<a href="{_COLAB_URL}">π¬ Colab</a> Β·
|
| 389 |
+
<a href="{_REPO_URL}">β GitHub</a>
|
| 390 |
+
</div>
|
| 391 |
+
""")
|
| 392 |
+
|
| 393 |
+
# ββ μ΄λ²€νΈ λ°μΈλ© ββ
|
| 394 |
+
analyzeBtn.click(
|
| 395 |
+
handleAnalyze,
|
| 396 |
+
inputs=queryInput,
|
| 397 |
+
outputs=[companyInfo, codeState, financeTable, topicSelect, sectionTable, sectionText],
|
| 398 |
+
)
|
| 399 |
+
queryInput.submit(
|
| 400 |
+
handleAnalyze,
|
| 401 |
+
inputs=queryInput,
|
| 402 |
+
outputs=[companyInfo, codeState, financeTable, topicSelect, sectionTable, sectionText],
|
| 403 |
+
)
|
| 404 |
|
| 405 |
+
sheetSelect.change(
|
| 406 |
+
handleFinance,
|
| 407 |
+
inputs=[codeState, sheetSelect],
|
| 408 |
+
outputs=financeTable,
|
| 409 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
|
| 411 |
+
topicSelect.change(
|
| 412 |
+
handleShow,
|
| 413 |
+
inputs=[codeState, topicSelect],
|
| 414 |
+
outputs=[sectionTable, sectionText],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
)
|
| 416 |
|
| 417 |
|
requirements.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
dartlab>=0.7.8
|
| 2 |
-
gradio>=
|
|
|
|
| 1 |
dartlab>=0.7.8
|
| 2 |
+
gradio>=6.0,<7
|