Spaces:
Runtime error
Runtime error
File size: 3,773 Bytes
3bb6b7c bf34294 3bb6b7c bf34294 3bb6b7c bf34294 3bb6b7c bf34294 3bb6b7c bf34294 3bb6b7c bf34294 3bb6b7c bf34294 3bb6b7c |
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 |
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("""
<style>
.code-container {
border-radius: 0.5rem;
padding: 1rem;
background-color: #f8f9fa;
border: 1px solid #dee2e6;
}
.fixed-code {
background-color: #e8f5e9;
}
.error-message {
color: #d32f2f;
font-weight: bold;
}
.warning-message {
color: #ffa000;
}
</style>
""", 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'<p class="error-message">β’ {error}</p>', unsafe_allow_html=True)
else:
st.success("No critical errors found!")
with tab2:
if results["warnings"]:
for warning in results["warnings"]:
st.markdown(f'<p class="warning-message">β’ {warning}</p>', 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('<div class="code-container fixed-code">', unsafe_allow_html=True)
st.code(results["fixed_code"], language="javascript")
st.markdown('</div>', unsafe_allow_html=True)
st.download_button(
"π Download Optimized Code",
data=results["fixed_code"],
file_name="optimized_script.pine",
mime="text/plain",
use_container_width=True
)
if __name__ == "__main__":
main() |