|
|
import streamlit as st |
|
|
import os |
|
|
from setup import page_setup |
|
|
from utilities import save_notebook, save_datasets |
|
|
from grammar_exec import execute |
|
|
from notebook import main_call |
|
|
import pandas as pd |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
col1, col2, col3 = st.columns([2, 4, 1]) |
|
|
with col2: |
|
|
st.title(":blue[Great] Lens π΅οΈββοΈ") |
|
|
|
|
|
|
|
|
st.subheader("π Upload Files") |
|
|
|
|
|
col1, col2 = st.columns(2) |
|
|
|
|
|
with col1: |
|
|
st.markdown("**Upload Notebook**") |
|
|
notebook = st.file_uploader( |
|
|
label='Select Jupyter Notebook', |
|
|
accept_multiple_files=False, |
|
|
type=['ipynb'], |
|
|
help="Upload a .ipynb file to analyze" |
|
|
) |
|
|
|
|
|
with col2: |
|
|
st.markdown("**Upload Datasets (Optional)**") |
|
|
datasets = st.file_uploader( |
|
|
label='Select Dataset Files', |
|
|
accept_multiple_files=True, |
|
|
type=['csv', 'xlsx', 'xls', 'json', 'txt', 'parquet'], |
|
|
help="Upload datasets that your notebook references" |
|
|
) |
|
|
|
|
|
|
|
|
if datasets: |
|
|
st.info(f"π {len(datasets)} dataset(s) uploaded: {', '.join([f.name for f in datasets])}") |
|
|
|
|
|
if notebook: |
|
|
st.success(f"π Notebook uploaded: {notebook.name}") |
|
|
|
|
|
|
|
|
save_notebook(notebook) |
|
|
if datasets: |
|
|
save_datasets(datasets) |
|
|
st.info("β
Datasets saved to notebook directory") |
|
|
|
|
|
results_tab, grammar_tab = st.tabs(['Execution', 'Grammar/Fact']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with grammar_tab: |
|
|
try: |
|
|
with st.spinner("π Analyzing grammar and facts..."): |
|
|
results = execute("/tmp/Notebook") |
|
|
|
|
|
if not results.empty: |
|
|
|
|
|
st.subheader("π Grammar & Style Analysis") |
|
|
|
|
|
if 'Grammar_Text' in results.columns and len(results['Grammar_Text'].dropna()) > 0: |
|
|
grammar_issues = results[results['Grammar_Text'].notna()] |
|
|
|
|
|
for idx, row in grammar_issues.iterrows(): |
|
|
if row['Is Grammar Error?']: |
|
|
st.warning(f"**Grammar Error:** {row['Grammar_Text']}") |
|
|
st.info(f"**Suggestion:** {row['Grammar_Suggestions']}") |
|
|
else: |
|
|
st.info(f"**Style Suggestion:** {row['Grammar_Text']}") |
|
|
st.success(f"**Improvement:** {row['Grammar_Suggestions']}") |
|
|
st.divider() |
|
|
|
|
|
st.subheader("π― Factual Accuracy Analysis") |
|
|
|
|
|
if 'Fact_Text' in results.columns and len(results['Fact_Text'].dropna()) > 0: |
|
|
fact_issues = results[results['Fact_Text'].notna()] |
|
|
|
|
|
for idx, row in fact_issues.iterrows(): |
|
|
st.error(f"**Factual Error:** {row['Fact_Text']}") |
|
|
st.success(f"**Correction:** {row['Fact_Suggestions']}") |
|
|
st.divider() |
|
|
|
|
|
|
|
|
with st.expander("π View Raw Results"): |
|
|
st.dataframe(results) |
|
|
else: |
|
|
st.success("β
No grammar or factual issues found!") |
|
|
|
|
|
except Exception as e: |
|
|
st.error(f"β Unable to process grammar/facts: {str(e)}") |
|
|
|
|
|
|
|
|
st.sidebar.markdown("## π‘ How to Use") |
|
|
st.sidebar.markdown(""" |
|
|
1. **Upload Notebook**: Select your .ipynb file |
|
|
2. **Upload Datasets**: Add any CSV, Excel, or other data files your notebook uses |
|
|
3. **Execution Tab**: See if your notebook runs successfully |
|
|
4. **Grammar/Fact Tab**: Check for text quality and factual accuracy |
|
|
|
|
|
### π§ Colab Support |
|
|
The tool automatically handles Google Colab specific code: |
|
|
- Replaces Drive mounts with local file access |
|
|
- Uses your uploaded datasets instead of Colab file uploads |
|
|
- Skips Colab-specific imports that won't work locally |
|
|
""") |
|
|
|
|
|
st.sidebar.markdown("## π Supported Formats") |
|
|
st.sidebar.markdown(""" |
|
|
**Notebooks:** .ipynb |
|
|
**Datasets:** .csv, .xlsx, .xls, .json, .txt, .parquet |
|
|
""") |