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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import json
|
4 |
+
from datetime import datetime, timedelta
|
5 |
+
import base64
|
6 |
+
import pandas as pd
|
7 |
+
import pydeck as pdk
|
8 |
+
from paper import (
|
9 |
+
literature_research_task, outline_task, draft_writing_task,
|
10 |
+
citation_task, editing_task, chatbot_task,
|
11 |
+
run_task
|
12 |
+
)
|
13 |
+
|
14 |
+
# st.set_page_config()
|
15 |
+
st.set_page_config(
|
16 |
+
page_title="AI Agent for Academic Research",
|
17 |
+
page_icon="π",
|
18 |
+
layout="wide",
|
19 |
+
initial_sidebar_state="expanded"
|
20 |
+
)
|
21 |
+
|
22 |
+
# ------------------------------------------
|
23 |
+
#
|
24 |
+
# ------------------------------------------
|
25 |
+
translations = {
|
26 |
+
"id": {
|
27 |
+
"page_title": "Agen AI untuk Penelitian Akademis",
|
28 |
+
"header": "Agen AI untuk Penelitian Akademis",
|
29 |
+
"create_itinerary": "Membuat Laporan Penelitian",
|
30 |
+
"trip_details": "Penelitian rinci",
|
31 |
+
"origin": "Research Topic",
|
32 |
+
"destination": "Judul penelitian",
|
33 |
+
"travel_dates": "Tanggal selesai",
|
34 |
+
"duration": "Jumlah halaman (pages)",
|
35 |
+
"preferences": "Keywords/Focus",
|
36 |
+
"special_requirements": "Additional Instructions",
|
37 |
+
"submit": "π Buatkan Laporan Penelitian",
|
38 |
+
"request_details": "Your Research Request",
|
39 |
+
"from": "Topic",
|
40 |
+
"when": "Due Date",
|
41 |
+
"budget": "Paper Type",
|
42 |
+
"travel_style": "Writing Style",
|
43 |
+
"live_agent_outputs": "Live Agent Outputs",
|
44 |
+
"full_itinerary": "Full Paper",
|
45 |
+
"details": "Details",
|
46 |
+
"download_share": "Download & Share",
|
47 |
+
"save_itinerary": "Save Your Paper",
|
48 |
+
"plan_another_trip": "π Generate Another Paper",
|
49 |
+
"about": "About",
|
50 |
+
"how_it_works": "How it works",
|
51 |
+
"travel_agents": "Research Agents",
|
52 |
+
"share_itinerary": "Share Your Paper",
|
53 |
+
"save_for_mobile": "Save for Mobile",
|
54 |
+
"built_with": "Built with β€οΈ for you",
|
55 |
+
"itinerary_ready": "Your Research Paper is Ready! π",
|
56 |
+
"personalized_experience": "Kami telah membuat makalah akademis yang dipersonalisasi berdasarkan masukan Anda. Lihat makalah Anda di bawah ini.",
|
57 |
+
"agent_activity": "Agent Activity",
|
58 |
+
"error_origin_destination": "Harap masukkan topik penelitian dan judul makalah",
|
59 |
+
"your_itinerary_file": "Your Paper File",
|
60 |
+
"text_format": "Text format - Can be opened in any text editor"
|
61 |
+
},
|
62 |
+
"en": {
|
63 |
+
"page_title": "AI Agent for Academic Research",
|
64 |
+
"header": "AI Agent for Academic Research",
|
65 |
+
"create_itinerary": "Generate Your Research Paper",
|
66 |
+
"trip_details": "Research Details",
|
67 |
+
"origin": "Research Topic",
|
68 |
+
"destination": "Paper Title",
|
69 |
+
"travel_dates": "Due Date",
|
70 |
+
"duration": "Paper Length (pages)",
|
71 |
+
"preferences": "Keywords/Focus",
|
72 |
+
"special_requirements": "Additional Instructions",
|
73 |
+
"submit": "π Generate My Research Paper",
|
74 |
+
"request_details": "Your Research Request",
|
75 |
+
"from": "Topic",
|
76 |
+
"when": "Due Date",
|
77 |
+
"budget": "Paper Type",
|
78 |
+
"travel_style": "Writing Style",
|
79 |
+
"live_agent_outputs": "Live Agent Outputs",
|
80 |
+
"full_itinerary": "Full Paper",
|
81 |
+
"details": "Details",
|
82 |
+
"download_share": "Download & Share",
|
83 |
+
"save_itinerary": "Save Your Paper",
|
84 |
+
"plan_another_trip": "π Generate Another Paper",
|
85 |
+
"about": "About",
|
86 |
+
"how_it_works": "How it works",
|
87 |
+
"travel_agents": "Research Agents",
|
88 |
+
"share_itinerary": "Share Your Paper",
|
89 |
+
"save_for_mobile": "Save for Mobile",
|
90 |
+
"built_with": "Built with β€οΈ for you",
|
91 |
+
"itinerary_ready": "Your Research Paper is Ready! π",
|
92 |
+
"personalized_experience": "We've created a personalized academic paper based on your inputs. Explore your paper below.",
|
93 |
+
"agent_activity": "Agent Activity",
|
94 |
+
"error_origin_destination": "Please enter both the research topic and paper title.",
|
95 |
+
"your_itinerary_file": "Your Paper File",
|
96 |
+
"text_format": "Text format - Can be opened in any text editor"
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
def t(key):
|
101 |
+
lang = st.session_state.get("selected_language", "id")
|
102 |
+
return translations[lang].get(key, key)
|
103 |
+
|
104 |
+
# ---------------------------
|
105 |
+
#
|
106 |
+
# ---------------------------
|
107 |
+
if 'selected_language' not in st.session_state:
|
108 |
+
st.session_state.selected_language = "id"
|
109 |
+
|
110 |
+
# ------------------------------------------
|
111 |
+
#
|
112 |
+
# ------------------------------------------
|
113 |
+
with st.sidebar:
|
114 |
+
language = st.selectbox(
|
115 |
+
"Language / Bahasa",
|
116 |
+
["Indonesia","English"]
|
117 |
+
)
|
118 |
+
lang_map = {
|
119 |
+
"Indonesia": "id",
|
120 |
+
"English": "en"
|
121 |
+
}
|
122 |
+
st.session_state.selected_language = lang_map.get(language, "id")
|
123 |
+
|
124 |
+
# ------------------------------------------
|
125 |
+
#
|
126 |
+
# ------------------------------------------
|
127 |
+
st.markdown("""
|
128 |
+
<style>
|
129 |
+
:root {
|
130 |
+
--primary: #3a86ff;
|
131 |
+
--primary-light: #4895ef;
|
132 |
+
--primary-dark: #2667ff;
|
133 |
+
--background: #f8f9fa;
|
134 |
+
--card-bg: #ffffff;
|
135 |
+
--text: #212529;
|
136 |
+
--border: #e9ecef;
|
137 |
+
}
|
138 |
+
.main-header {
|
139 |
+
font-size: 2.5rem;
|
140 |
+
color: var(--primary-dark);
|
141 |
+
text-align: center;
|
142 |
+
margin-bottom: 0.8rem;
|
143 |
+
font-weight: 700;
|
144 |
+
}
|
145 |
+
.modern-card {
|
146 |
+
background-color: var(--card-bg);
|
147 |
+
border-radius: 10px;
|
148 |
+
padding: 1.2rem;
|
149 |
+
margin-bottom: 1.2rem;
|
150 |
+
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
|
151 |
+
border: 1px solid var(--border);
|
152 |
+
}
|
153 |
+
</style>
|
154 |
+
""", unsafe_allow_html=True)
|
155 |
+
|
156 |
+
def get_download_link(text_content, filename):
|
157 |
+
b64 = base64.b64encode(text_content.encode()).decode()
|
158 |
+
href = f'<a class="download-link" href="data:text/plain;base64,{b64}" download="{filename}"><i>π₯</i> {t("save_itinerary")}</a>'
|
159 |
+
return href
|
160 |
+
|
161 |
+
def display_modern_progress(current_step, total_steps=5):
|
162 |
+
if 'progress_steps' not in st.session_state:
|
163 |
+
st.session_state.progress_steps = {
|
164 |
+
0: {'status': 'pending', 'name': t("trip_details")},
|
165 |
+
1: {'status': 'pending', 'name': t("about")},
|
166 |
+
2: {'status': 'pending', 'name': t("live_agent_outputs")},
|
167 |
+
3: {'status': 'pending', 'name': t("download_share")},
|
168 |
+
4: {'status': 'pending', 'name': t("full_itinerary")}
|
169 |
+
}
|
170 |
+
for i in range(total_steps):
|
171 |
+
if i < current_step:
|
172 |
+
st.session_state.progress_steps[i]['status'] = 'complete'
|
173 |
+
elif i == current_step:
|
174 |
+
st.session_state.progress_steps[i]['status'] = 'active'
|
175 |
+
else:
|
176 |
+
st.session_state.progress_steps[i]['status'] = 'pending'
|
177 |
+
progress_percentage = (current_step / total_steps) * 100
|
178 |
+
st.progress(progress_percentage / 100)
|
179 |
+
st.markdown("<div>Progress: " + str(progress_percentage) + "% completed.</div>")
|
180 |
+
return progress_percentage
|
181 |
+
|
182 |
+
def update_step_status(step_index, status):
|
183 |
+
if 'progress_steps' in st.session_state and step_index in st.session_state.progress_steps:
|
184 |
+
st.session_state.progress_steps[step_index]['status'] = status
|
185 |
+
|
186 |
+
def run_task_with_logs(task, input_text, log_container, output_container, results_key=None):
|
187 |
+
log_message = f"π€ Starting {task.agent.role}..."
|
188 |
+
st.session_state.log_messages.append(log_message)
|
189 |
+
with log_container:
|
190 |
+
st.markdown("### " + t("agent_activity"))
|
191 |
+
for msg in st.session_state.log_messages:
|
192 |
+
st.markdown(msg)
|
193 |
+
result = run_task(task, input_text)
|
194 |
+
if results_key:
|
195 |
+
st.session_state.results[results_key] = result
|
196 |
+
log_message = f"β
{task.agent.role} completed!"
|
197 |
+
st.session_state.log_messages.append(log_message)
|
198 |
+
with log_container:
|
199 |
+
st.markdown("### " + t("agent_activity"))
|
200 |
+
for msg in st.session_state.log_messages:
|
201 |
+
st.markdown(msg)
|
202 |
+
with output_container:
|
203 |
+
st.markdown(f"### {task.agent.role} Output")
|
204 |
+
st.markdown("<div class='agent-output'>" + result + "</div>", unsafe_allow_html=True)
|
205 |
+
return result
|
206 |
+
|
207 |
+
if 'generated_itinerary' not in st.session_state:
|
208 |
+
st.session_state.generated_itinerary = None
|
209 |
+
if 'generation_complete' not in st.session_state:
|
210 |
+
st.session_state.generation_complete = False
|
211 |
+
if 'current_step' not in st.session_state:
|
212 |
+
st.session_state.current_step = 0
|
213 |
+
if 'results' not in st.session_state:
|
214 |
+
st.session_state.results = {
|
215 |
+
"literature_review": "",
|
216 |
+
"outline": "",
|
217 |
+
"draft": "",
|
218 |
+
"citations": "",
|
219 |
+
"edited": ""
|
220 |
+
}
|
221 |
+
if 'log_messages' not in st.session_state:
|
222 |
+
st.session_state.log_messages = []
|
223 |
+
if 'form_submitted' not in st.session_state:
|
224 |
+
st.session_state.form_submitted = False
|
225 |
+
|
226 |
+
st.markdown(f"""
|
227 |
+
<div style="text-align: center;">
|
228 |
+
<img src="https://img.icons8.com/fluency/96/book.png" width="90">
|
229 |
+
<h1 class="main-header">{t("header")}</h1>
|
230 |
+
<p>Hasilkan makalah penelitian pribadi Anda dengan agen yang berbasis AI.</p>
|
231 |
+
</div>
|
232 |
+
""", unsafe_allow_html=True)
|
233 |
+
st.markdown('<hr>', unsafe_allow_html=True)
|
234 |
+
|
235 |
+
with st.sidebar:
|
236 |
+
st.markdown("""
|
237 |
+
<div style="text-align: center;">
|
238 |
+
<img src="https://img.icons8.com/fluency/96/book.png" width="80">
|
239 |
+
<h3>Asisten AI untuk Penelitian Akademik</h3>
|
240 |
+
<p>Pembuatan laporan dibantu AI</p>
|
241 |
+
</div>
|
242 |
+
""", unsafe_allow_html=True)
|
243 |
+
st.markdown('<div class="modern-card">', unsafe_allow_html=True)
|
244 |
+
st.markdown("### " + t("about"))
|
245 |
+
st.info("Alat ini menghasilkan makalah penelitian akademis yang dipersonalisasi berdasarkan masukan Anda. Isi formulir dan biarkan agen spesialis kami menyusun makalah Anda!")
|
246 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
247 |
+
st.markdown('<div class="modern-card">', unsafe_allow_html=True)
|
248 |
+
st.markdown("### " + t("how_it_works"))
|
249 |
+
st.markdown("""
|
250 |
+
<ol>
|
251 |
+
<li>Masukkan detail penelitian Anda</li>
|
252 |
+
<li>AI melakukan penelitian literatur</li>
|
253 |
+
<li>Membuat kerangka makalah</li>
|
254 |
+
<li>Buat draf dan edit makalah Anda</li>
|
255 |
+
<li>Unduh makalah akhir Anda</li>
|
256 |
+
</ol>
|
257 |
+
""", unsafe_allow_html=True)
|
258 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
259 |
+
|
260 |
+
if not st.session_state.generation_complete:
|
261 |
+
st.markdown('<div class="modern-card">', unsafe_allow_html=True)
|
262 |
+
st.markdown("<h3>" + t("create_itinerary") + "</h3>", unsafe_allow_html=True)
|
263 |
+
st.markdown("<p>Isi rincian di bawah ini</p>", unsafe_allow_html=True)
|
264 |
+
|
265 |
+
with st.form("research_form"):
|
266 |
+
col1, col2 = st.columns(2)
|
267 |
+
with col1:
|
268 |
+
research_topic = st.text_input(t("origin"), placeholder="e.g., Manfaat Teh untuk kesehatan manusia")
|
269 |
+
paper_title = st.text_input(t("destination"), placeholder="e.g., Hasil penelitian terbaru tentang manfaat teh untuk kesehatan manusia")
|
270 |
+
due_date = st.date_input(t("travel_dates"), min_value=datetime.now())
|
271 |
+
with col2:
|
272 |
+
paper_length = st.slider(t("duration"), min_value=5, max_value=50, value=10)
|
273 |
+
paper_type_options = ["Journal", "Conference", "Thesis", "Review"]
|
274 |
+
paper_type = st.selectbox(t("budget"), paper_type_options, help="Select the type of paper")
|
275 |
+
writing_style = st.multiselect(t("travel_style"), options=["Formal", "Technical", "Creative"], default=["Formal"])
|
276 |
+
additional_instructions = st.text_area(t("special_requirements"), placeholder="Instruksi atau persyaratan tambahan apa pun...")
|
277 |
+
keywords = st.text_area(t("preferences"), placeholder="Masukkan kata kunci atau area fokus, dipisahkan dengan koma")
|
278 |
+
submit_button = st.form_submit_button(t("submit"))
|
279 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
280 |
+
|
281 |
+
if submit_button:
|
282 |
+
if not research_topic or not paper_title:
|
283 |
+
st.error(t("error_origin_destination"))
|
284 |
+
else:
|
285 |
+
st.session_state.form_submitted = True
|
286 |
+
st.session_state.research_topic = research_topic
|
287 |
+
user_input = {
|
288 |
+
"research_topic": research_topic,
|
289 |
+
"paper_title": paper_title,
|
290 |
+
"due_date": due_date.strftime("%Y-%m-%d"),
|
291 |
+
"paper_length": str(paper_length),
|
292 |
+
"paper_type": paper_type,
|
293 |
+
"writing_style": ", ".join(writing_style),
|
294 |
+
"keywords": keywords,
|
295 |
+
"additional_instructions": additional_instructions
|
296 |
+
}
|
297 |
+
st.session_state.user_input = user_input
|
298 |
+
input_context = f"""Research Request Details:
|
299 |
+
Research Topic: {user_input['research_topic']}
|
300 |
+
Paper Title: {user_input['paper_title']}
|
301 |
+
Due Date: {user_input['due_date']}
|
302 |
+
Paper Length: {user_input['paper_length']} pages
|
303 |
+
Paper Type: {user_input['paper_type']}
|
304 |
+
Writing Style: {user_input['writing_style']}
|
305 |
+
Keywords/Focus: {user_input['keywords']}
|
306 |
+
Additional Instructions: {user_input['additional_instructions']}
|
307 |
+
"""
|
308 |
+
llm_language_instructions = {
|
309 |
+
"en": "Please output the response in English.",
|
310 |
+
"id": "Please output the response in Bahasa Indonesia."
|
311 |
+
}
|
312 |
+
selected_lang = st.session_state.get("selected_language", "id")
|
313 |
+
language_instruction = llm_language_instructions.get(selected_lang, "Please output the response in Bahasa Indonesia.")
|
314 |
+
modified_input_context = language_instruction + "\n" + input_context
|
315 |
+
|
316 |
+
st.markdown("<div>Sedang memproses...</div>", unsafe_allow_html=True)
|
317 |
+
st.session_state.current_step = 0
|
318 |
+
update_step_status(0, 'active')
|
319 |
+
progress_placeholder = st.empty()
|
320 |
+
with progress_placeholder.container():
|
321 |
+
display_modern_progress(st.session_state.current_step)
|
322 |
+
log_container = st.container()
|
323 |
+
st.session_state.log_messages = []
|
324 |
+
output_container = st.container()
|
325 |
+
st.session_state.results = {}
|
326 |
+
|
327 |
+
# Step 1: Literature Research
|
328 |
+
literature_review = run_task_with_logs(
|
329 |
+
literature_research_task,
|
330 |
+
modified_input_context.format(topic=user_input['research_topic'], keywords=user_input['keywords']),
|
331 |
+
log_container,
|
332 |
+
output_container,
|
333 |
+
"literature_review"
|
334 |
+
)
|
335 |
+
update_step_status(0, 'complete')
|
336 |
+
st.session_state.current_step = 1
|
337 |
+
update_step_status(1, 'active')
|
338 |
+
with progress_placeholder.container():
|
339 |
+
display_modern_progress(st.session_state.current_step)
|
340 |
+
|
341 |
+
# Step 2: Generate Outline
|
342 |
+
outline = run_task_with_logs(
|
343 |
+
outline_task,
|
344 |
+
modified_input_context.format(topic=user_input['research_topic']),
|
345 |
+
log_container,
|
346 |
+
output_container,
|
347 |
+
"outline"
|
348 |
+
)
|
349 |
+
update_step_status(1, 'complete')
|
350 |
+
st.session_state.current_step = 2
|
351 |
+
update_step_status(2, 'active')
|
352 |
+
with progress_placeholder.container():
|
353 |
+
display_modern_progress(st.session_state.current_step)
|
354 |
+
|
355 |
+
# Step 3: Draft Writing
|
356 |
+
draft = run_task_with_logs(
|
357 |
+
draft_writing_task,
|
358 |
+
modified_input_context.format(topic=user_input['research_topic']),
|
359 |
+
log_container,
|
360 |
+
output_container,
|
361 |
+
"draft"
|
362 |
+
)
|
363 |
+
update_step_status(2, 'complete')
|
364 |
+
st.session_state.current_step = 3
|
365 |
+
update_step_status(3, 'active')
|
366 |
+
with progress_placeholder.container():
|
367 |
+
display_modern_progress(st.session_state.current_step)
|
368 |
+
|
369 |
+
# Step 4: Citation Generation
|
370 |
+
citations = run_task_with_logs(
|
371 |
+
citation_task,
|
372 |
+
modified_input_context.format(topic=user_input['research_topic']),
|
373 |
+
log_container,
|
374 |
+
output_container,
|
375 |
+
"citations"
|
376 |
+
)
|
377 |
+
update_step_status(3, 'complete')
|
378 |
+
st.session_state.current_step = 4
|
379 |
+
update_step_status(4, 'active')
|
380 |
+
with progress_placeholder.container():
|
381 |
+
display_modern_progress(st.session_state.current_step)
|
382 |
+
|
383 |
+
# Step 5: Editing and Polishing
|
384 |
+
edited = run_task_with_logs(
|
385 |
+
editing_task,
|
386 |
+
modified_input_context.format(topic=user_input['research_topic']),
|
387 |
+
log_container,
|
388 |
+
output_container,
|
389 |
+
"edited"
|
390 |
+
)
|
391 |
+
update_step_status(4, 'complete')
|
392 |
+
st.session_state.current_step = 5
|
393 |
+
with progress_placeholder.container():
|
394 |
+
display_modern_progress(st.session_state.current_step)
|
395 |
+
|
396 |
+
full_paper = f"""Research Paper:
|
397 |
+
{input_context}
|
398 |
+
Literature Review:
|
399 |
+
{literature_review}
|
400 |
+
Outline:
|
401 |
+
{outline}
|
402 |
+
Draft:
|
403 |
+
{draft}
|
404 |
+
Citations:
|
405 |
+
{citations}
|
406 |
+
Edited Version:
|
407 |
+
{edited}
|
408 |
+
"""
|
409 |
+
st.session_state.generated_itinerary = full_paper
|
410 |
+
st.session_state.generation_complete = True
|
411 |
+
date_str = datetime.now().strftime("%Y-%m-%d")
|
412 |
+
st.session_state.filename = f"{user_input['paper_title'].replace(' ', '_')}_{date_str}_paper.txt"
|
413 |
+
|
414 |
+
if st.session_state.generation_complete:
|
415 |
+
st.markdown(f"""
|
416 |
+
<div class="modern-card">
|
417 |
+
<div style="text-align: center;">
|
418 |
+
<h2>{t("itinerary_ready")}</h2>
|
419 |
+
<p>{t("personalized_experience")}</p>
|
420 |
+
</div>
|
421 |
+
</div>
|
422 |
+
""", unsafe_allow_html=True)
|
423 |
+
|
424 |
+
#
|
425 |
+
full_paper_tab, details_tab, download_tab, visualization_tab, chatbot_tab = st.tabs([
|
426 |
+
"ποΈ " + t("full_itinerary"),
|
427 |
+
"πΌ " + t("details"),
|
428 |
+
"πΎ " + t("download_share"),
|
429 |
+
"π Visualization",
|
430 |
+
"π€ Chatbot"
|
431 |
+
])
|
432 |
+
|
433 |
+
with full_paper_tab:
|
434 |
+
st.text_area("Your Research Paper", st.session_state.generated_itinerary, height=600)
|
435 |
+
|
436 |
+
with details_tab:
|
437 |
+
agent_tabs = st.tabs(["π Literature Review", "π Outline", "βοΈ Draft", "π Citations", "ποΈ Edited Version"])
|
438 |
+
with agent_tabs[0]:
|
439 |
+
st.markdown("### Literature Review")
|
440 |
+
st.markdown(st.session_state.results.get("literature_review", ""))
|
441 |
+
with agent_tabs[1]:
|
442 |
+
st.markdown("### Outline")
|
443 |
+
st.markdown(st.session_state.results.get("outline", ""))
|
444 |
+
with agent_tabs[2]:
|
445 |
+
st.markdown("### Draft")
|
446 |
+
st.markdown(st.session_state.results.get("draft", ""))
|
447 |
+
with agent_tabs[3]:
|
448 |
+
st.markdown("### Citations")
|
449 |
+
st.markdown(st.session_state.results.get("citations", ""))
|
450 |
+
with agent_tabs[4]:
|
451 |
+
st.markdown("### Edited Version")
|
452 |
+
st.markdown(st.session_state.results.get("edited", ""))
|
453 |
+
|
454 |
+
with download_tab:
|
455 |
+
col1, col2 = st.columns([2, 1])
|
456 |
+
with col1:
|
457 |
+
st.markdown("### " + t("save_itinerary"))
|
458 |
+
st.markdown("Download your research paper to access it offline or share with your colleagues.")
|
459 |
+
st.markdown(f"""
|
460 |
+
<div style="background-color: #f8f9fa; padding: 15px; border-radius: 10px; margin-top: 20px;">
|
461 |
+
<h4>{t("your_itinerary_file")}</h4>
|
462 |
+
<p style="font-size: 0.9rem; color: #6c757d;">{t("text_format")}</p>
|
463 |
+
</div>
|
464 |
+
""", unsafe_allow_html=True)
|
465 |
+
st.markdown("<div>" + get_download_link(st.session_state.generated_itinerary, st.session_state.filename) + "</div>", unsafe_allow_html=True)
|
466 |
+
st.markdown("### " + t("share_itinerary"))
|
467 |
+
st.markdown("*Coming soon: Email your paper or share via social media.*")
|
468 |
+
with col2:
|
469 |
+
st.markdown("### " + t("save_for_mobile"))
|
470 |
+
st.markdown("*Coming soon: QR code for easy access on your phone*")
|
471 |
+
|
472 |
+
with visualization_tab:
|
473 |
+
st.markdown("### Visualization")
|
474 |
+
st.markdown("A conceptual diagram or visualization related to your research paper can be displayed here. (Feature under development)")
|
475 |
+
|
476 |
+
with chatbot_tab:
|
477 |
+
st.markdown("### AI Chat")
|
478 |
+
if "chat_history" not in st.session_state:
|
479 |
+
st.session_state.chat_history = []
|
480 |
+
user_message = st.text_input("Input:", key="chat_input")
|
481 |
+
if st.button("Kirim", key="send_button"):
|
482 |
+
if user_message:
|
483 |
+
response = run_task(chatbot_task, user_message)
|
484 |
+
st.session_state.chat_history.append({
|
485 |
+
"speaker": "μ¬μ©μ",
|
486 |
+
"message": user_message,
|
487 |
+
"time": datetime.now()
|
488 |
+
})
|
489 |
+
st.session_state.chat_history.append({
|
490 |
+
"speaker": "AI",
|
491 |
+
"message": response,
|
492 |
+
"time": datetime.now()
|
493 |
+
})
|
494 |
+
st.markdown("<div style='max-height:400px; overflow-y:auto; padding:10px; border:1px solid #eaeaea; border-radius:6px;'>", unsafe_allow_html=True)
|
495 |
+
for chat in st.session_state.chat_history:
|
496 |
+
time_str = chat["time"].strftime("%H:%M:%S")
|
497 |
+
st.markdown(f"**{chat['speaker']}** ({time_str}): {chat['message']}")
|
498 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
499 |
+
|
500 |
+
st.markdown("""
|
501 |
+
<div style="text-align: center; padding: 20px; color: #6c757d; font-size: 0.8rem;">
|
502 |
+
<p>""" + t("built_with") + """</p>
|
503 |
+
</div>
|
504 |
+
""", unsafe_allow_html=True)
|