Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,78 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
def suggest_trade(prompt):
|
| 7 |
-
result = generator(prompt, max_length=100)[0]["generated_text"]
|
| 8 |
-
return result
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
title="Crypto-Walk",
|
| 15 |
-
description="Enter your market view or question and get AI-generated trading advice."
|
| 16 |
-
)
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from config import SessionManager, validate_all_keys
|
| 3 |
+
from services.market import get_market_data, get_current_price
|
| 4 |
+
from ai.service import AIService
|
| 5 |
|
| 6 |
+
session = SessionManager()
|
| 7 |
+
ai = AIService()
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
def set_keys(openai_key, kucoin_key, kucoin_secret, kucoin_passphrase, provider):
|
| 11 |
+
session.set_keys(openai_key, kucoin_key, kucoin_secret, kucoin_passphrase, provider)
|
| 12 |
+
ok, msg = validate_all_keys(session)
|
| 13 |
+
return msg
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
|
| 16 |
+
def clear_keys():
|
| 17 |
+
session.clear()
|
| 18 |
+
return "β
Session cleared"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def generate(symbol, timeframe, leverage, amount):
|
| 22 |
+
if not session.is_ready():
|
| 23 |
+
return {"error": "π Enter API keys first."}
|
| 24 |
+
market_data = get_market_data(symbol, timeframe, session)
|
| 25 |
+
current_price = get_current_price(symbol, session)
|
| 26 |
+
result = ai.generate(
|
| 27 |
+
symbol=symbol,
|
| 28 |
+
leverage=leverage,
|
| 29 |
+
trade_amount=amount,
|
| 30 |
+
current_price=current_price,
|
| 31 |
+
market_data=market_data,
|
| 32 |
+
provider=session.provider,
|
| 33 |
+
openai_key=session.openai_key,
|
| 34 |
+
hf_token=session.hf_token,
|
| 35 |
+
)
|
| 36 |
+
return (
|
| 37 |
+
result.to_prompt_dict()
|
| 38 |
+
if result
|
| 39 |
+
else {"error": "Failed to generate suggestion"}
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
with gr.Blocks(theme=gr.themes.Base(default_color_scheme="dark")) as ui:
|
| 44 |
+
gr.Markdown("# πΉ AI Crypto Trader")
|
| 45 |
+
|
| 46 |
+
with gr.Accordion("π API Keys", open=True):
|
| 47 |
+
openai_key = gr.Textbox(label="OpenAI Key", type="password")
|
| 48 |
+
kucoin_key = gr.Textbox(label="KuCoin Key", type="password")
|
| 49 |
+
kucoin_secret = gr.Textbox(label="KuCoin Secret", type="password")
|
| 50 |
+
kucoin_pass = gr.Textbox(label="KuCoin Passphrase", type="password")
|
| 51 |
+
provider = gr.Radio(
|
| 52 |
+
["OpenAI", "HuggingFace"], value="OpenAI", label="AI Provider"
|
| 53 |
+
)
|
| 54 |
+
connect = gr.Button("Connect")
|
| 55 |
+
status = gr.Textbox(label="Connection Status")
|
| 56 |
+
connect.click(
|
| 57 |
+
set_keys,
|
| 58 |
+
inputs=[openai_key, kucoin_key, kucoin_secret, kucoin_pass, provider],
|
| 59 |
+
outputs=status,
|
| 60 |
+
)
|
| 61 |
+
gr.Button("β Clear Session").click(clear_keys, outputs=status)
|
| 62 |
+
|
| 63 |
+
gr.Markdown("---")
|
| 64 |
+
|
| 65 |
+
with gr.Row():
|
| 66 |
+
symbol = gr.Textbox(label="Symbol", value="SOLUSDTM")
|
| 67 |
+
timeframe = gr.Dropdown(
|
| 68 |
+
["15m", "1h", "4h", "1d"], label="Timeframe", value="15m"
|
| 69 |
+
)
|
| 70 |
+
leverage = gr.Slider(10, 75, step=1, value=20, label="Leverage")
|
| 71 |
+
amount = gr.Number(label="Trade Amount ($)", value=100)
|
| 72 |
+
|
| 73 |
+
output = gr.JSON(label="AI Suggestion")
|
| 74 |
+
gr.Button("π Generate Suggestion").click(
|
| 75 |
+
generate, inputs=[symbol, timeframe, leverage, amount], outputs=output
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
ui.launch()
|