Spaces:
Sleeping
Sleeping
File size: 2,279 Bytes
6ee159d d0a587a 4c3edc4 be76f2f d0a587a f114d79 d0a587a be76f2f 6ee159d be76f2f 6ee159d 49382de 6ee159d be76f2f 6ee159d 4c3edc4 be76f2f 4c3edc4 6ee159d 4c3edc4 d0a587a 81f7613 d0a587a 81f7613 d0a587a 9e59807 d0a587a 81f7613 d0a587a e227d9a 4c3edc4 d0a587a be76f2f d0a587a e227d9a d0a587a e227d9a |
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 |
import gradio as gr
from transformers import AutoProcessor, AutoModelForVision2Seq
from PIL import Image
import io
# 🔍 تحميل النموذج والمُعالِج
model_id = "HuggingFaceM4/sla-v1"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForVision2Seq.from_pretrained(model_id).to("cuda" if torch.cuda.is_available() else "cpu")
# 💬 تعليمات الذكاء الاصطناعي لتكون خبير تداول
SYSTEM_PROMPT = """
You are a professional technical analyst with 10 years of experience in financial markets.
Analyze the chart provided and answer the following:
1. What is the current trend? (Uptrend / Downtrend / Sideways)
2. Are there any key support/resistance levels?
3. What technical indicators do you see? (RSI, MACD, Bollinger Bands...)
4. Suggest a trade idea: Entry point, Stop Loss, Take Profit
5. Timeframe and Risk/Reward ratio
6. Strategy name and explanation
Answer in Arabic in a professional tone.
"""
def analyze_chart(image):
if image is None:
return "❌ لم يتم تحميل أي صورة."
try:
# تحويل الصورة إلى RGB
img = image.convert("RGB")
# إنشاء prompt شامل
text = f"Question: {SYSTEM_PROMPT}\nAnswer:"
# المعالجة
inputs = processor(images=img, text=text, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
# التوليد
generated_ids = model.generate(**inputs, max_new_tokens=256)
response = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
return response.strip()
except Exception as e:
return f"❌ حدث خطأ أثناء التحليل: {str(e)}"
# 🖥️ واجهة Gradio
interface = gr.Interface(
fn=analyze_chart,
inputs=gr.Image(type="pil", label="تحميل مخطط التداول"),
outputs=gr.Markdown(label="تحليل الذكاء الاصطناعي"),
title="🤖 منصة تحليل التداول الذكية (نسخة مجانية)",
description="استخدم الذكاء الاصطناعي المحلي لتحليل مخططات التداول وإعطاء تحليل احترافي.",
theme="default",
)
if __name__ == "__main__":
interface.launch() |