djharga commited on
Commit
5e72fca
·
verified ·
1 Parent(s): a2d7b74

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ from datetime import datetime
5
+ from transformers import pipeline
6
+ import pandas_ta as ta
7
+ import requests
8
+
9
+ # 1. تحميل نموذجك المدرب (أو تدريبه هنا)
10
+ def load_model():
11
+ try:
12
+ # مثال: تحميل نموذج من Hugging Face Hub
13
+ return pipeline("text-classification", model="finiteautomata/bertweet-base-sentiment-analysis")
14
+ except:
15
+ return None
16
+
17
+ model = load_model()
18
+
19
+ # 2. جلب بيانات العملات
20
+ def fetch_crypto_data(coin_id="bitcoin", days=30):
21
+ url = f"https://api.coingecko.com/api/v3/coins/{coin_id}/market_chart?vs_currency=usd&days={days}"
22
+ data = requests.get(url).json()
23
+ df = pd.DataFrame(data['prices'], columns=['timestamp', 'price'])
24
+ df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
25
+ return df
26
+
27
+ # 3. تحليل فني + تنبؤ
28
+ def analyze(coin):
29
+ df = fetch_crypto_data(coin)
30
+
31
+ # حساب المؤشرات الفنية
32
+ df['RSI'] = ta.rsi(df['price'])
33
+ df['MACD'] = ta.macd(df['price'])['MACD_12_26_9']
34
+
35
+ # تنبؤ مبسط (استبدل بنموذجك الفعلي)
36
+ last_price = df['price'].iloc[-1]
37
+ prediction = last_price * (1 + np.random.uniform(-0.1, 0.1))
38
+
39
+ # تحليل المشاعر
40
+ sentiment = model("Cryptocurrency market is booming")[0]['label'] if model else "Neutral"
41
+
42
+ return {
43
+ "price": last_price,
44
+ "prediction": prediction,
45
+ "rsi": df['RSI'].iloc[-1],
46
+ "sentiment": sentiment
47
+ }
48
+
49
+ # 4. واجهة Gradio
50
+ with gr.Blocks() as demo:
51
+ gr.Markdown("## 🚀 محلل العملات المشفرة بالذكاء الاصطناعي")
52
+
53
+ with gr.Row():
54
+ coin = gr.Dropdown(["bitcoin", "ethereum"], label="اختر العملة")
55
+ btn = gr.Button("حلل الآن")
56
+
57
+ with gr.Row():
58
+ price = gr.Textbox(label="السعر الحالي")
59
+ prediction = gr.Textbox(label="التنبؤ")
60
+
61
+ with gr.Row():
62
+ rsi = gr.Textbox(label="مؤشر RSI")
63
+ sentiment = gr.Textbox(label="مشاعر السوق")
64
+
65
+ btn.click(
66
+ fn=lambda c: analyze(c),
67
+ inputs=coin,
68
+ outputs=[price, prediction, rsi, sentiment]
69
+ )
70
+
71
+ demo.launch()