Spaces:
Runtime error
Runtime error
File size: 2,264 Bytes
5e72fca | 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 | import gradio as gr
import pandas as pd
import numpy as np
from datetime import datetime
from transformers import pipeline
import pandas_ta as ta
import requests
# 1. تحميل نموذجك المدرب (أو تدريبه هنا)
def load_model():
try:
# مثال: تحميل نموذج من Hugging Face Hub
return pipeline("text-classification", model="finiteautomata/bertweet-base-sentiment-analysis")
except:
return None
model = load_model()
# 2. جلب بيانات العملات
def fetch_crypto_data(coin_id="bitcoin", days=30):
url = f"https://api.coingecko.com/api/v3/coins/{coin_id}/market_chart?vs_currency=usd&days={days}"
data = requests.get(url).json()
df = pd.DataFrame(data['prices'], columns=['timestamp', 'price'])
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
return df
# 3. تحليل فني + تنبؤ
def analyze(coin):
df = fetch_crypto_data(coin)
# حساب المؤشرات الفنية
df['RSI'] = ta.rsi(df['price'])
df['MACD'] = ta.macd(df['price'])['MACD_12_26_9']
# تنبؤ مبسط (استبدل بنموذجك الفعلي)
last_price = df['price'].iloc[-1]
prediction = last_price * (1 + np.random.uniform(-0.1, 0.1))
# تحليل المشاعر
sentiment = model("Cryptocurrency market is booming")[0]['label'] if model else "Neutral"
return {
"price": last_price,
"prediction": prediction,
"rsi": df['RSI'].iloc[-1],
"sentiment": sentiment
}
# 4. واجهة Gradio
with gr.Blocks() as demo:
gr.Markdown("## 🚀 محلل العملات المشفرة بالذكاء الاصطناعي")
with gr.Row():
coin = gr.Dropdown(["bitcoin", "ethereum"], label="اختر العملة")
btn = gr.Button("حلل الآن")
with gr.Row():
price = gr.Textbox(label="السعر الحالي")
prediction = gr.Textbox(label="التنبؤ")
with gr.Row():
rsi = gr.Textbox(label="مؤشر RSI")
sentiment = gr.Textbox(label="مشاعر السوق")
btn.click(
fn=lambda c: analyze(c),
inputs=coin,
outputs=[price, prediction, rsi, sentiment]
)
demo.launch() |