Spaces:
Sleeping
Sleeping
File size: 2,870 Bytes
39b3f7a 77bb8ad 39b3f7a 77bb8ad 39b3f7a c92b203 77bb8ad 39b3f7a 77bb8ad 0630c49 77bb8ad c92b203 77bb8ad c92b203 77bb8ad |
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 |
import gradio as gr
from config import SessionManager, validate_all_keys
from services.market import get_market_data, get_current_price
from ai.service import AIService
session = SessionManager()
ai = AIService()
def set_keys(
openai_key, kucoin_key, kucoin_secret, kucoin_passphrase, provider, hf_token
):
session.set_keys(
openai_key, kucoin_key, kucoin_secret, kucoin_passphrase, provider, hf_token
)
ok, msg = validate_all_keys(session)
return msg
def clear_keys():
session.clear()
return "β
Session cleared"
def generate(symbol, timeframe, leverage, amount):
if not session.is_ready():
return {"error": "π Enter API keys first."}
market_data = get_market_data(symbol, timeframe, session)
current_price = get_current_price(symbol, session)
result = ai.generate(
symbol=symbol,
leverage=leverage,
trade_amount=amount,
current_price=current_price,
market_data=market_data,
provider=session.provider,
openai_key=session.openai_key,
hf_token=session.hf_token,
)
return (
result.to_prompt_dict()
if result
else {"error": "Failed to generate suggestion"}
)
with gr.Blocks(theme=gr.themes.Monochrome()) as ui:
gr.Markdown("# πΉ AI Crypto Trader")
with gr.Accordion("π API Keys", open=True):
openai_key = gr.Textbox(label="OpenAI Key", type="password")
kucoin_key = gr.Textbox(label="KuCoin Key", type="password")
kucoin_secret = gr.Textbox(label="KuCoin Secret", type="password")
kucoin_pass = gr.Textbox(label="KuCoin Passphrase", type="password")
hf_token = gr.Textbox(label="HF Token (if using HuggingFace)", type="password")
provider = gr.Radio(
["OpenAI", "HuggingFace"], value="OpenAI", label="AI Provider"
)
connect = gr.Button("Connect")
status = gr.Textbox(label="Connection Status")
connect.click(
set_keys,
inputs=[
openai_key,
kucoin_key,
kucoin_secret,
kucoin_pass,
provider,
hf_token,
],
outputs=status,
)
gr.Button("β Clear Session").click(clear_keys, outputs=status)
gr.Markdown("---")
with gr.Row():
symbol = gr.Textbox(label="Symbol", value="SOLUSDTM")
timeframe = gr.Dropdown(
["15m", "1h", "4h", "1d"], label="Timeframe", value="15m"
)
leverage = gr.Slider(10, 75, step=1, value=20, label="Leverage")
amount = gr.Number(label="Trade Amount ($)", value=100)
output = gr.JSON(label="AI Suggestion")
gr.Button("π Generate Suggestion").click(
generate, inputs=[symbol, timeframe, leverage, amount], outputs=output
)
ui.launch()
|