Spaces:
Sleeping
Sleeping
Commit ยท
5231ae5
1
Parent(s): 632e995
Enhance UI with custom theme, improved layout and visual elements
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from utils import (
|
|
| 6 |
evaluate_expertise,
|
| 7 |
get_crypto_data,
|
| 8 |
)
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def run_chat(crypto, data_span):
|
|
@@ -46,25 +47,105 @@ def run_chat(crypto, data_span):
|
|
| 46 |
yield chat_history, chat_history
|
| 47 |
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
)
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
state = gr.State([])
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
start_btn.click(
|
| 65 |
-
|
| 66 |
[crypto_dropdown, span_dropdown],
|
| 67 |
-
[
|
|
|
|
| 68 |
)
|
| 69 |
|
| 70 |
demo.launch()
|
|
|
|
| 6 |
evaluate_expertise,
|
| 7 |
get_crypto_data,
|
| 8 |
)
|
| 9 |
+
import random
|
| 10 |
|
| 11 |
|
| 12 |
def run_chat(crypto, data_span):
|
|
|
|
| 47 |
yield chat_history, chat_history
|
| 48 |
|
| 49 |
|
| 50 |
+
# Define a custom theme with vibrant colors
|
| 51 |
+
custom_theme = gr.themes.Soft().set(
|
| 52 |
+
primary_hue="indigo",
|
| 53 |
+
secondary_hue="emerald",
|
| 54 |
+
neutral_hue="slate",
|
| 55 |
+
font=[gr.themes.GoogleFont("Poppins"), "ui-sans-serif", "system-ui", "sans-serif"],
|
| 56 |
+
)
|
| 57 |
|
| 58 |
+
# Create emoji indicators for cryptocurrencies
|
| 59 |
+
crypto_emojis = {
|
| 60 |
+
"btc": "โฟ Bitcoin",
|
| 61 |
+
"eth": "ฮ Ethereum",
|
| 62 |
+
"virtual": "๐ฎ Virtual",
|
| 63 |
+
"bnb": "๐ช BNB"
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
# Create time span emojis
|
| 67 |
+
time_emojis = {
|
| 68 |
+
"24h": "โฐ 24 Hours",
|
| 69 |
+
"7d": "๐
7 Days",
|
| 70 |
+
"14d": "๐๏ธ 14 Days",
|
| 71 |
+
"30d": "๐ 30 Days",
|
| 72 |
+
"60d": "๐ 60 Days"
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
with gr.Blocks(theme=custom_theme) as demo:
|
| 76 |
+
with gr.Box(css="padding: 20px; border-radius: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);"):
|
| 77 |
+
gr.Markdown(
|
| 78 |
+
"""
|
| 79 |
+
# ๐ง TranchVest AI - Crypto Risk Assessment
|
| 80 |
+
### Analyze cryptocurrency behavior with AI-powered insights
|
| 81 |
+
"""
|
| 82 |
)
|
| 83 |
+
|
| 84 |
+
with gr.Row(equal_height=True):
|
| 85 |
+
with gr.Column(scale=1):
|
| 86 |
+
gr.Markdown("### ๐ Configuration")
|
| 87 |
+
with gr.Box(css="padding: 15px; border-radius: 8px; background: rgba(0, 0, 0, 0.03);"):
|
| 88 |
+
crypto_dropdown = gr.Dropdown(
|
| 89 |
+
list(crypto_emojis.values()),
|
| 90 |
+
label="Select Cryptocurrency",
|
| 91 |
+
value="โฟ Bitcoin",
|
| 92 |
+
container=True,
|
| 93 |
+
interactive=True
|
| 94 |
+
)
|
| 95 |
+
span_dropdown = gr.Dropdown(
|
| 96 |
+
list(time_emojis.values()),
|
| 97 |
+
label="Select Time Frame",
|
| 98 |
+
value="๐
7 Days",
|
| 99 |
+
container=True,
|
| 100 |
+
interactive=True
|
| 101 |
+
)
|
| 102 |
+
start_btn = gr.Button(
|
| 103 |
+
"๐ Start Analysis",
|
| 104 |
+
variant="primary",
|
| 105 |
+
size="lg"
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
with gr.Column(scale=2):
|
| 109 |
+
chatbot = gr.Chatbot(
|
| 110 |
+
height=600,
|
| 111 |
+
bubble_full_width=False,
|
| 112 |
+
show_copy_button=True,
|
| 113 |
+
avatar_images=("https://em-content.zobj.net/source/microsoft-teams/363/robot_1f916.png", None),
|
| 114 |
+
css="border-radius: 12px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);"
|
| 115 |
+
)
|
| 116 |
|
| 117 |
+
# Tips and information section
|
| 118 |
+
with gr.Accordion("โน๏ธ About This Tool", open=False):
|
| 119 |
+
gr.Markdown(
|
| 120 |
+
"""
|
| 121 |
+
### How to use this tool:
|
| 122 |
+
1. **Select a cryptocurrency** from the dropdown menu
|
| 123 |
+
2. **Choose a time frame** for analysis
|
| 124 |
+
3. **Click 'Start Analysis'** to begin the AI-driven assessment
|
| 125 |
+
4. The AI will ask a series of questions about risk factors
|
| 126 |
+
5. At the end, you'll receive a comprehensive risk evaluation
|
| 127 |
+
|
| 128 |
+
This tool helps evaluate investment risk factors for different cryptocurrencies based on market behavior and trends.
|
| 129 |
+
"""
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
# Add hidden state
|
| 133 |
state = gr.State([])
|
| 134 |
|
| 135 |
+
# Process the input values from the dropdowns to match the expected format in run_chat
|
| 136 |
+
def preprocess_input(crypto, span):
|
| 137 |
+
# Extract the crypto code from the dropdown display value
|
| 138 |
+
crypto_code = next((code for code, display in crypto_emojis.items() if display == crypto), "btc")
|
| 139 |
+
# Extract the span code from the dropdown display value
|
| 140 |
+
span_code = next((code for code, display in time_emojis.items() if display == span), "7d")
|
| 141 |
+
return crypto_code, span_code
|
| 142 |
+
|
| 143 |
+
# Connect the button click
|
| 144 |
start_btn.click(
|
| 145 |
+
lambda c, s: preprocess_input(c, s),
|
| 146 |
[crypto_dropdown, span_dropdown],
|
| 147 |
+
[lambda x, y: run_chat(x, y)[0], lambda x, y: run_chat(x, y)[1]],
|
| 148 |
+
_js="() => [{}, {}]" # This ensures the outputs are passed correctly
|
| 149 |
)
|
| 150 |
|
| 151 |
demo.launch()
|