CoolFace
Apppublic

Tradinator1/CoinSenseAI

sourceHugging Faceupdated 1y agoView on Hugging Face
1likes
ui.py75 linesDownload Raw Back to root
1import gradio as gr2from backend.main import process_portfolio3 4def create_ui():5    def analyze_portfolio(portfolio_input):6        market_summary, risk_report, trend_summary, rebalance, suggestions, reallocation = process_portfolio(portfolio_input)7 8        def format_section(title, text, emoji, bg_color):9            lines = [line.strip() for line in text.split("\n") if line.strip()]10            bullet_list = "<br>".join([f"โ€ข {line}" for line in lines])11            return f"""12            <div style="13                background-color:{bg_color};14                padding:15px;15                border-radius:12px;16                margin-bottom:15px;17                box-shadow: 0 2px 8px rgba(0,0,0,0.08);18                color:#000000;19                font-weight:500;20            ">21                <h3 style="margin-top:0; color:#000000;">{emoji} {title}</h3>22                <p style="margin:0; color:#000000;">{bullet_list}</p>23            </div>24            """25 26        return (27            format_section("Market Summary", market_summary, "๐Ÿ“Š", "#d6eaff"),28            format_section("Risk Report", risk_report, "โš ๏ธ", "#ffe0b2"),29            format_section("Trend Summary", trend_summary, "๐Ÿ“ˆ", "#c8e6c9"),30            format_section("Rebalance Plan", rebalance, "๐Ÿ”„", "#b9f6ca"),31            format_section("Suggestions", suggestions, "๐Ÿ’ก", "#fff59d"),32            format_section("Reallocation Plan", reallocation, "๐Ÿ“‚", "#d1c4e9")33        )34 35    with gr.Blocks(theme=gr.themes.Soft()) as ui:36        gr.Markdown(37           """38    <h2 style="color:#5850ec; font-weight:600; font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; text-align:center;">39    ๐Ÿ’ฐ CoinSenseAI โ€” AI Crypto Portfolio Assistant40    </h2>41    """42        )43        gr.Markdown(44            "<p style='text-align:center; font-size:16px; color:#1a237e;'>"45            "Enter your portfolio in the format: <b>BTC 0.5, ETH $1000, ADA 300</b></p>"46        )47 48        portfolio_input = gr.Textbox(49            label="Your Portfolio",50            placeholder="Example: BTC 0.5, ETH $1000, ADA 300"51        )52        submit_btn = gr.Button("Analyze Portfolio", variant="primary")53 54        market_summary_box = gr.HTML()55        risk_report_box = gr.HTML()56        trend_summary_box = gr.HTML()57        rebalance_box = gr.HTML()58        suggestions_box = gr.HTML()59        reallocation_box = gr.HTML()60 61        submit_btn.click(62            analyze_portfolio,63            inputs=portfolio_input,64            outputs=[65                market_summary_box,66                risk_report_box,67                trend_summary_box,68                rebalance_box,69                suggestions_box,70                reallocation_box71            ]72        )73 74    return ui75