fokan's picture
Upload app.py with huggingface_hub
67706d2 verified
import gradio as gr
from unsloth import FastLanguageModel
print("Loading Gemma...")
model, tokenizer = FastLanguageModel.from_pretrained(
"./gemma_xauusd", max_seq_length=2048, load_in_4bit=True
)
FastLanguageModel.for_inference(model)
print("Gemma ready!")
def predict(price, sma50, sma200, rsi, atr, returns):
trend = "uptrend" if price > sma200 else "downtrend"
momentum = "bullish" if price > sma50 else "bearish"
prompt = f"""Analyze XAU/USD: Price ${price:.2f}, Trend: {trend}, Momentum: {momentum}, RSI: {rsi:.1f}. Direction?"""
inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=50, temperature=0.3)
result = tokenizer.decode(outputs[0])
if "BULLISH" in result.upper():
return {"sentiment": "BULLISH", "signal": 1.0, "confidence": 0.8}
elif "BEARISH" in result.upper():
return {"sentiment": "BEARISH", "signal": -1.0, "confidence": 0.8}
else:
return {"sentiment": "NEUTRAL", "signal": 0.0, "confidence": 0.5}
demo = gr.Interface(
fn=predict,
inputs=[
gr.Number(label="Price", value=2650),
gr.Number(label="SMA 50", value=2640),
gr.Number(label="SMA 200", value=2620),
gr.Number(label="RSI", value=65),
gr.Number(label="ATR", value=12),
gr.Number(label="Returns %", value=0.5),
],
outputs=gr.JSON(label="Prediction"),
title="Gemma XAU/USD Analyzer",
description="AI-powered market analysis",
api_name="predict"
)
demo.launch()