Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -431,6 +431,63 @@ with st.sidebar:
|
|
| 431 |
st.error(f"β Generation failed: {str(e)}")
|
| 432 |
st.write("π‘ Try adjusting your parameters or check your API key")
|
| 433 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 434 |
# Quick Actions
|
| 435 |
st.markdown("---")
|
| 436 |
st.subheader("β‘ Quick Actions")
|
|
|
|
| 431 |
st.error(f"β Generation failed: {str(e)}")
|
| 432 |
st.write("π‘ Try adjusting your parameters or check your API key")
|
| 433 |
|
| 434 |
+
# Data Management
|
| 435 |
+
st.markdown("---")
|
| 436 |
+
st.subheader("π Data Management")
|
| 437 |
+
|
| 438 |
+
# Import functionality
|
| 439 |
+
with st.expander("π₯ Import Scripts from JSONL", expanded=False):
|
| 440 |
+
st.info("π‘ Upload a JSONL file to import scripts as reference data for the RAG system")
|
| 441 |
+
|
| 442 |
+
uploaded_file = st.file_uploader(
|
| 443 |
+
"Choose a JSONL file",
|
| 444 |
+
type=['jsonl'],
|
| 445 |
+
help="Upload your script data file (e.g., anya_scripts.jsonl)"
|
| 446 |
+
)
|
| 447 |
+
|
| 448 |
+
if uploaded_file is not None:
|
| 449 |
+
# Save uploaded file temporarily
|
| 450 |
+
import tempfile
|
| 451 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.jsonl') as tmp_file:
|
| 452 |
+
tmp_file.write(uploaded_file.getvalue())
|
| 453 |
+
tmp_path = tmp_file.name
|
| 454 |
+
|
| 455 |
+
col1, col2 = st.columns(2)
|
| 456 |
+
with col1:
|
| 457 |
+
if st.button("π₯ Import Scripts", type="primary", use_container_width=True):
|
| 458 |
+
with st.spinner("Importing scripts..."):
|
| 459 |
+
try:
|
| 460 |
+
from db import import_jsonl
|
| 461 |
+
count = import_jsonl(tmp_path)
|
| 462 |
+
st.success(f"β
Successfully imported {count} scripts!")
|
| 463 |
+
st.balloons()
|
| 464 |
+
time.sleep(1)
|
| 465 |
+
st.rerun()
|
| 466 |
+
except Exception as e:
|
| 467 |
+
st.error(f"β Import failed: {str(e)}")
|
| 468 |
+
finally:
|
| 469 |
+
# Clean up temp file
|
| 470 |
+
import os
|
| 471 |
+
try:
|
| 472 |
+
os.unlink(tmp_path)
|
| 473 |
+
except:
|
| 474 |
+
pass
|
| 475 |
+
|
| 476 |
+
with col2:
|
| 477 |
+
if st.button("π Preview Data", use_container_width=True):
|
| 478 |
+
try:
|
| 479 |
+
import json
|
| 480 |
+
# Show first few lines as preview
|
| 481 |
+
content = uploaded_file.getvalue().decode('utf-8')
|
| 482 |
+
lines = content.strip().split('\n')[:3]
|
| 483 |
+
st.write("**Preview (first 3 scripts):**")
|
| 484 |
+
for i, line in enumerate(lines, 1):
|
| 485 |
+
if line.strip():
|
| 486 |
+
data = json.loads(line)
|
| 487 |
+
st.write(f"**Script {i}:** {data.get('theme', 'No title')} - {data.get('model_name', 'Unknown creator')}")
|
| 488 |
+
except Exception as e:
|
| 489 |
+
st.error(f"Preview failed: {str(e)}")
|
| 490 |
+
|
| 491 |
# Quick Actions
|
| 492 |
st.markdown("---")
|
| 493 |
st.subheader("β‘ Quick Actions")
|