-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb_interface.py
More file actions
402 lines (320 loc) ยท 13.3 KB
/
web_interface.py
File metadata and controls
402 lines (320 loc) ยท 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# web_interface.py - Streamlit ์น ์ธํฐํ์ด์ค
import streamlit as st
import sys
import os
sys.path.append('src')
from src.core import PaperSections
from treellm_system import TreeLLMSystem
from utils.pdf_processor import PDFProcessor, RelatedPaperProcessor
import json
def init_session_state():
"""์ธ์
์ํ ์ด๊ธฐํ"""
if 'analysis_results' not in st.session_state:
st.session_state.analysis_results = None
if 'treellm' not in st.session_state:
st.session_state.treellm = TreeLLMSystem()
def display_header():
"""ํค๋ ํ์"""
st.set_page_config(
page_title="TreeLLM - AI Paper Analyzer",
page_icon="๐ณ",
layout="wide"
)
st.title("๐ณ TreeLLM")
st.subtitle("AI Agent ๊ธฐ๋ฐ ๋
ผ๋ฌธ ๋ถ์ ์์คํ
")
st.markdown("---")
def paper_input_section():
"""๋
ผ๋ฌธ ์
๋ ฅ ์น์
"""
st.header("๐ ๋
ผ๋ฌธ ์
๋ ฅ")
input_method = st.radio(
"์
๋ ฅ ๋ฐฉ์ ์ ํ:",
["ํ
์คํธ ์ง์ ์
๋ ฅ", "PDF ํ์ผ ์
๋ก๋"]
)
paper_sections = None
if input_method == "ํ
์คํธ ์ง์ ์
๋ ฅ":
paper_sections = text_input_interface()
else:
paper_sections = pdf_upload_interface()
return paper_sections
def text_input_interface():
"""ํ
์คํธ ์ง์ ์
๋ ฅ ์ธํฐํ์ด์ค"""
col1, col2 = st.columns(2)
with col1:
introduction = st.text_area(
"Introduction",
height=150,
placeholder="๋
ผ๋ฌธ์ Introduction ์น์
์ ์
๋ ฅํ์ธ์..."
)
method = st.text_area(
"Method",
height=150,
placeholder="Method ์น์
์ ์
๋ ฅํ์ธ์..."
)
discussion = st.text_area(
"Discussion",
height=150,
placeholder="Discussion ์น์
์ ์
๋ ฅํ์ธ์..."
)
with col2:
related_work = st.text_area(
"Related Work",
height=150,
placeholder="Related Work ์น์
์ ์
๋ ฅํ์ธ์..."
)
experiments = st.text_area(
"Experiments",
height=150,
placeholder="Experiments ์น์
์ ์
๋ ฅํ์ธ์..."
)
conclusion = st.text_area(
"Conclusion",
height=150,
placeholder="Conclusion ์น์
์ ์
๋ ฅํ์ธ์..."
)
if any([introduction, related_work, method, experiments, discussion, conclusion]):
return PaperSections(
introduction=introduction,
related_work=related_work,
method=method,
experiments=experiments,
discussion=discussion,
conclusion=conclusion
)
return None
def pdf_upload_interface():
"""PDF ์
๋ก๋ ์ธํฐํ์ด์ค"""
uploaded_file = st.file_uploader(
"๋
ผ๋ฌธ PDF ํ์ผ์ ์
๋ก๋ํ์ธ์",
type=['pdf'],
help="PDF์์ ์๋์ผ๋ก ์น์
์ ์ถ์ถํฉ๋๋ค"
)
if uploaded_file is not None:
with st.spinner("PDF ํ์ผ ์ฒ๋ฆฌ ์ค..."):
try:
# ์์ ํ์ผ๋ก ์ ์ฅ
temp_path = f"temp_{uploaded_file.name}"
with open(temp_path, "wb") as f:
f.write(uploaded_file.getbuffer())
# ์น์
์ถ์ถ
sections_dict = PDFProcessor.extract_sections_from_pdf(temp_path)
# ๋ฉํ๋ฐ์ดํฐ ์ถ์ถ
metadata = PDFProcessor.extract_metadata_from_pdf(temp_path)
# ์์ ํ์ผ ์ญ์
os.remove(temp_path)
# ๊ฒฐ๊ณผ ํ์
st.success("โ
PDF ์ฒ๋ฆฌ ์๋ฃ!")
if metadata.get('title'):
st.info(f"๐ ์ ๋ชฉ: {metadata['title']}")
if metadata.get('page_count'):
st.info(f"๐ ํ์ด์ง ์: {metadata['page_count']}")
# ์ถ์ถ๋ ์น์
๋ฏธ๋ฆฌ๋ณด๊ธฐ
with st.expander("์ถ์ถ๋ ์น์
๋ฏธ๋ฆฌ๋ณด๊ธฐ"):
for section_name, content in sections_dict.items():
if content.strip():
st.text_area(
f"{section_name.title()}",
value=content[:200] + "..." if len(content) > 200 else content,
height=80,
disabled=True
)
return PaperSections(**sections_dict)
except Exception as e:
st.error(f"โ PDF ์ฒ๋ฆฌ ์คํจ: {e}")
return None
def related_papers_section():
"""๊ด๋ จ ๋
ผ๋ฌธ ์น์
"""
st.header("๐ ๊ด๋ จ ๋
ผ๋ฌธ ๋น๊ต (์ ํ์ฌํญ)")
with st.expander("๊ด๋ จ ๋
ผ๋ฌธ ์
๋ก๋"):
st.markdown("""
๊ด๋ จ ๋
ผ๋ฌธ๋ค์ ์
๋ก๋ํ๋ฉด ๋ ์ ํํ ๋น๊ต ๋ถ์์ด ๊ฐ๋ฅํฉ๋๋ค.
- ๊ถ์ฅ: 3-10ํธ์ ๊ด๋ จ ๋
ผ๋ฌธ
- ์ง์ ํ์: PDF
""")
uploaded_papers = st.file_uploader(
"๊ด๋ จ ๋
ผ๋ฌธ PDF ํ์ผ๋ค",
type=['pdf'],
accept_multiple_files=True,
help="์ฌ๋ฌ ํ์ผ์ ์ ํํ ์ ์์ต๋๋ค"
)
if uploaded_papers:
st.success(f"โ
{len(uploaded_papers)}ํธ์ ๊ด๋ จ ๋
ผ๋ฌธ ์
๋ก๋๋จ")
# ๊ฐ๋จํ ์ ๋ณด ํ์
for i, paper in enumerate(uploaded_papers, 1):
st.text(f"{i}. {paper.name}")
return uploaded_papers
return None
def analysis_options_section():
"""๋ถ์ ์ต์
์น์
"""
st.header("๐ ๋ถ์ ์ต์
")
col1, col2 = st.columns(2)
with col1:
st.markdown("**USENIX ๊ธฐ์ค ๊ฒ์ฆ** (ํ์)")
usenix_agents = st.multiselect(
"USENIX Agent ์ ํ:",
["OriginalityAgent", "LessonExtractionAgent", "AssumptionAgent"],
default=["OriginalityAgent", "LessonExtractionAgent"],
help="USENIX Guidelines ๊ธฐ์ค์ผ๋ก ๋
ผ๋ฌธ์ ํ๊ฐํฉ๋๋ค"
)
with col2:
st.markdown("**์ถ๊ฐ ๋ถ์ ์ต์
**")
enable_comparison = st.checkbox(
"๊ด๋ จ ๋
ผ๋ฌธ ๋น๊ต ๋ถ์",
help="์
๋ก๋๋ ๊ด๋ จ ๋
ผ๋ฌธ๋ค๊ณผ ๋น๊ตํฉ๋๋ค"
)
show_token_usage = st.checkbox(
"ํ ํฐ ์ฌ์ฉ๋ ํ์",
help="์์ ํ ํฐ ์ฌ์ฉ๋๊ณผ ๋น์ฉ์ ํ์ํฉ๋๋ค"
)
return usenix_agents, enable_comparison, show_token_usage
def display_analysis_results(results):
"""๋ถ์ ๊ฒฐ๊ณผ ํ์"""
st.header("๐ ๋ถ์ ๊ฒฐ๊ณผ")
# ์ ์ฒด ์์ฝ
summary = results['integrated_summary']
col1, col2, col3 = st.columns(3)
with col1:
st.metric("์ ์ฒด ์ ์", f"{summary['overall_score']:.2f}/5.0")
with col2:
st.metric("๊ฐ์ ์ ์", f"{summary['total_suggestions']}๊ฐ")
with col3:
improvement_count = len(summary['priority_improvements'])
st.metric("์ฐ์ ๊ฐ์ ", f"{improvement_count}๊ฐ")
# Agent๋ณ ์์ธ ๊ฒฐ๊ณผ
st.subheader("๐ค Agent๋ณ ๋ถ์ ๊ฒฐ๊ณผ")
for agent_name, result in results['usenix_analysis'].items():
with st.expander(f"{agent_name} ๊ฒฐ๊ณผ", expanded=True):
# ์ ์ ํ์
st.markdown("**๐ ์ ์**")
score_cols = st.columns(len(result.scores))
for i, (criterion, score) in enumerate(result.scores.items()):
with score_cols[i]:
# ์ ์์ ๋ฐ๋ฅธ ์์
if score >= 4.0:
color = "๐ข"
elif score >= 3.0:
color = "๐ก"
else:
color = "๐ด"
st.metric(
criterion,
f"{score:.1f}",
delta=None,
help=f"5์ ๋ง์ ๊ธฐ์ค {color}"
)
# ๋ฐ๊ฒฌ์ฌํญ
st.markdown("**๐ ์ฃผ์ ๋ฐ๊ฒฌ์ฌํญ**")
for finding in result.findings:
st.write(f"โข {finding}")
# ๊ฐ์ ์ ์
st.markdown("**๐ก ๊ฐ์ ์ ์**")
for suggestion in result.suggestions:
st.write(f"โข {suggestion}")
# ๊ด๋ จ ๋
ผ๋ฌธ ๋น๊ต ๊ฒฐ๊ณผ
if results.get('comparison_analysis'):
st.subheader("๐ ๊ด๋ จ ๋
ผ๋ฌธ ๋น๊ต ๊ฒฐ๊ณผ")
comp_result = results['comparison_analysis']
with st.expander("๋น๊ต ๋ถ์ ๊ฒฐ๊ณผ", expanded=True):
# ๋น๊ต ์ ์
st.markdown("**๐ ๋น๊ต ์ ์**")
comp_cols = st.columns(len(comp_result.scores))
for i, (criterion, score) in enumerate(comp_result.scores.items()):
with comp_cols[i]:
st.metric(criterion, f"{score:.1f}/5.0")
# ๋น๊ต ๋ฐ๊ฒฌ์ฌํญ
st.markdown("**๐ ๋น๊ต ๋ถ์ ๋ฐ๊ฒฌ์ฌํญ**")
for finding in comp_result.findings:
st.write(f"โข {finding}")
# ๊ฒฐ๊ณผ ๋ค์ด๋ก๋
st.subheader("๐พ ๊ฒฐ๊ณผ ๋ค์ด๋ก๋")
# JSON ํํ๋ก ๋ค์ด๋ก๋
results_json = json.dumps(results, ensure_ascii=False, indent=2, default=str)
st.download_button(
label="๐ฅ ๋ถ์ ๊ฒฐ๊ณผ ๋ค์ด๋ก๋ (JSON)",
data=results_json,
file_name="treellm_analysis_results.json",
mime="application/json"
)
def sidebar_info():
"""์ฌ์ด๋๋ฐ ์ ๋ณด"""
st.sidebar.title("โน๏ธ TreeLLM ์ ๋ณด")
st.sidebar.markdown("""
### ๐ ์ง์ ๊ธฐ๋ฅ
- USENIX Guidelines ๊ธฐ์ค ๊ฒ์ฆ
- Agent ๊ธฐ๋ฐ ์ ๋ฌธ ๋ถ์
- ๊ด๋ จ ๋
ผ๋ฌธ ๋น๊ต ๋ถ์
- PDF ์๋ ์น์
์ถ์ถ
- ๊ฒฐ๊ณผ ๋ค์ด๋ก๋
### ๐ค ์ฌ์ฉ ๊ฐ๋ฅํ Agent
- **OriginalityAgent**: ๋
์ฐฝ์ฑ ํ๊ฐ
- **LessonExtractionAgent**: ๊ตํ ์ถ์ถ
- **AssumptionAgent**: ๊ฐ์ ์ฌํญ ๋ถ์
### ๐ก ์ฌ์ฉ ํ
1. ๋
ผ๋ฌธ์ ๋ชจ๋ ์น์
์ ์
๋ ฅํ์ธ์
2. ๊ด๋ จ ๋
ผ๋ฌธ์ ์
๋ก๋ํ๋ฉด ๋ ์ ํํฉ๋๋ค
3. ๊ฒฐ๊ณผ๋ฅผ JSON์ผ๋ก ์ ์ฅํ ์ ์์ต๋๋ค
""")
st.sidebar.markdown("---")
st.sidebar.markdown("**๊ฐ๋ฐํ**: TreeLLM Team")
st.sidebar.markdown("**๋ฒ์ **: v0.1.0")
def main():
"""๋ฉ์ธ ์น ์ธํฐํ์ด์ค"""
init_session_state()
display_header()
# 1. ๋
ผ๋ฌธ ์
๋ ฅ
paper_sections = paper_input_section()
# 2. ๊ด๋ จ ๋
ผ๋ฌธ ์
๋ก๋
uploaded_papers = related_papers_section()
# 3. ๋ถ์ ์ต์
selected_agents, enable_comparison, show_token_usage = analysis_options_section()
# 4. ํ ํฐ ์ฌ์ฉ๋ ํ์
if show_token_usage and paper_sections:
st.subheader("๐ฐ ์์ ํ ํฐ ์ฌ์ฉ๋")
token_usage = st.session_state.treellm.get_agent_token_usage()
total_tokens = sum(token_usage[agent] for agent in selected_agents if agent in token_usage)
estimated_cost = total_tokens * 0.00003 # GPT-4 ๊ธฐ์ค
col1, col2 = st.columns(2)
with col1:
st.metric("์์ ํ ํฐ", f"{total_tokens:,}")
with col2:
st.metric("์์ ๋น์ฉ", f"${estimated_cost:.3f}")
with st.expander("Agent๋ณ ํ ํฐ ์ฌ์ฉ๋"):
for agent in selected_agents:
if agent in token_usage:
st.text(f"{agent}: {token_usage[agent]:,} ํ ํฐ")
# 5. ๋ถ์ ์คํ ๋ฒํผ
st.markdown("---")
if st.button("๐ ๋
ผ๋ฌธ ๋ถ์ ์์", type="primary", use_container_width=True):
if not paper_sections:
st.error("โ ๋
ผ๋ฌธ ๋ด์ฉ์ ์
๋ ฅํด์ฃผ์ธ์.")
return
if not selected_agents:
st.error("โ ์ต์ ํ๋์ USENIX Agent๋ฅผ ์ ํํด์ฃผ์ธ์.")
return
# ๋ถ์ ์คํ
with st.spinner("๐ ๋
ผ๋ฌธ ๋ถ์ ์ค... (1-2๋ถ ์์)"):
try:
# ๊ด๋ จ ๋
ผ๋ฌธ ์ฒ๋ฆฌ
related_papers_data = None
if uploaded_papers and enable_comparison:
# PDF ์ฒ๋ฆฌ (์ค์ ๊ตฌํ์์๋ RelatedPaperProcessor ์ฌ์ฉ)
related_papers_data = [
{"title": paper.name, "year": 2023}
for paper in uploaded_papers
]
# ๋ถ์ ์คํ
results = st.session_state.treellm.analyze_paper(
paper_sections=paper_sections,
uploaded_papers=related_papers_data,
selected_agents=selected_agents
)
st.session_state.analysis_results = results
st.success("โ
๋ถ์ ์๋ฃ!")
except Exception as e:
st.error(f"โ ๋ถ์ ์ค ์ค๋ฅ ๋ฐ์: {e}")
return
# 6. ๊ฒฐ๊ณผ ํ์
if st.session_state.analysis_results:
display_analysis_results(st.session_state.analysis_results)
if __name__ == "__main__":
sidebar_info()
main()