import streamlit as st from pine_parser import PineScriptParser import os from dotenv import load_dotenv # Load environment variables load_dotenv() # Configure page st.set_page_config( page_title="Pine Script Analyzer Pro", page_icon="🧠", layout="wide" ) # Custom CSS for better UI st.markdown(""" """, unsafe_allow_html=True) def main(): st.title("🧠 Pine Script Analyzer Pro") st.caption("Professional-grade analysis and optimization for TradingView Pine Script") with st.expander("📝 Paste Your Pine Script Code", expanded=True): user_code = st.text_area( "Paste your Pine Script code here:", height=300, placeholder="""//@version=5 indicator("My Indicator") plot(close)""", label_visibility="collapsed" ) if st.button("🔍 Analyze & Optimize Code", use_container_width=True): if not user_code.strip(): st.error("Please enter Pine Script code to analyze") else: with st.spinner("Analyzing code with professional-grade tools..."): try: parser = PineScriptParser(user_code) results = { "version": parser.detect_version() or "Unknown", "errors": parser.find_errors(), "warnings": parser.find_warnings(), "optimizations": parser.find_optimizations(), "fixed_code": parser.generate_fixed_code() } display_results(results) except Exception as e: st.error(f"Professional analysis failed: {str(e)}") def display_results(results): """Display analysis results in professional UI""" # Version and summary col1, col2 = st.columns(2) with col1: st.metric("Detected Version", results["version"]) with col2: st.metric("Issues Found", f"{len(results['errors'])} Errors, {len(results['warnings'])} Warnings") # Tabs for different analysis aspects tab1, tab2, tab3, tab4 = st.tabs(["🚨 Errors", "⚠️ Warnings", "✨ Optimizations", "✅ Fixed Code"]) with tab1: if results["errors"]: for error in results["errors"]: st.markdown(f'
', unsafe_allow_html=True) else: st.success("No critical errors found!") with tab2: if results["warnings"]: for warning in results["warnings"]: st.markdown(f'', unsafe_allow_html=True) else: st.success("No warnings detected!") with tab3: if results["optimizations"]: for opt in results["optimizations"]: st.info(f"• {opt}") else: st.success("Code is already optimized!") with tab4: st.markdown('