Spaces:
Runtime error
Runtime error
| 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() |