Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,50 @@
|
|
1 |
-
import
|
|
|
|
|
2 |
from PIL import Image
|
|
|
3 |
import io
|
4 |
-
import gradio as gr
|
5 |
-
import os
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
#
|
13 |
SYSTEM_PROMPT = """
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
1.
|
18 |
-
2.
|
19 |
-
3.
|
20 |
-
4.
|
21 |
-
5.
|
22 |
-
6.
|
23 |
|
24 |
-
|
25 |
"""
|
26 |
|
27 |
-
# 📊 الدالة الرئيسية لتحليل الصورة
|
28 |
def analyze_chart(image):
|
29 |
if image is None:
|
30 |
return "❌ لم يتم تحميل أي صورة."
|
31 |
-
|
32 |
try:
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
except Exception as e:
|
41 |
return f"❌ حدث خطأ أثناء التحليل: {str(e)}"
|
42 |
|
@@ -45,11 +53,11 @@ interface = gr.Interface(
|
|
45 |
fn=analyze_chart,
|
46 |
inputs=gr.Image(type="bytes", label="تحميل مخطط التداول"),
|
47 |
outputs=gr.Markdown(label="تحليل الذكاء الاصطناعي"),
|
48 |
-
title="🤖 منصة تحليل التداول الذكية",
|
49 |
-
description="
|
50 |
-
theme="default"
|
|
|
51 |
)
|
52 |
|
53 |
-
# تشغيل التطبيق
|
54 |
if __name__ == "__main__":
|
55 |
interface.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoProcessor, LlavaForConditionalGeneration
|
3 |
+
import torch
|
4 |
from PIL import Image
|
5 |
+
import requests
|
6 |
import io
|
|
|
|
|
7 |
|
8 |
+
# 📦 تحميل النموذج والمُعالِج
|
9 |
+
model_id = "llava-hf/llava-1.5-7b-hf"
|
10 |
+
model = LlavaForConditionalGeneration.from_pretrained(model_id, device_map="auto")
|
11 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
12 |
|
13 |
+
# 💬 تعليمات الذكاء الاصطناعي لتكون خبير تداول
|
14 |
SYSTEM_PROMPT = """
|
15 |
+
You are a professional technical analyst with 10 years of experience in financial markets.
|
16 |
+
Analyze the chart provided and answer the following:
|
17 |
|
18 |
+
1. What is the current trend? (Uptrend / Downtrend / Sideways)
|
19 |
+
2. Are there any key support/resistance levels?
|
20 |
+
3. What technical indicators do you see? (RSI, MACD, etc.)
|
21 |
+
4. Suggest a trade idea: Entry point, Stop Loss, Take Profit
|
22 |
+
5. Timeframe and Risk/Reward ratio
|
23 |
+
6. Strategy name and explanation
|
24 |
|
25 |
+
Answer in Arabic in a professional tone.
|
26 |
"""
|
27 |
|
|
|
28 |
def analyze_chart(image):
|
29 |
if image is None:
|
30 |
return "❌ لم يتم تحميل أي صورة."
|
31 |
+
|
32 |
try:
|
33 |
+
# تحويل الصورة إلى تنسيق مناسب للنموذج
|
34 |
+
img = Image.open(io.BytesIO(image)).convert("RGB")
|
35 |
+
|
36 |
+
# إعداد prompt
|
37 |
+
prompt = f"<image>\nUSER: {SYSTEM_PROMPT}\nASSISTANT:"
|
38 |
+
|
39 |
+
# المعالجة
|
40 |
+
inputs = processor(prompt, images=img, return_tensors='pt').to(0, torch.float16)
|
41 |
+
|
42 |
+
# التوليد
|
43 |
+
output = model.generate(**inputs, max_new_tokens=512)
|
44 |
+
response = processor.decode(output[0], skip_special_tokens=True)
|
45 |
+
|
46 |
+
return response.split("ASSISTANT:")[-1].strip()
|
47 |
+
|
48 |
except Exception as e:
|
49 |
return f"❌ حدث خطأ أثناء التحليل: {str(e)}"
|
50 |
|
|
|
53 |
fn=analyze_chart,
|
54 |
inputs=gr.Image(type="bytes", label="تحميل مخطط التداول"),
|
55 |
outputs=gr.Markdown(label="تحليل الذكاء الاصطناعي"),
|
56 |
+
title="🤖 منصة تحليل التداول الذكية (بدون API)",
|
57 |
+
description="استخدم الذكاء الاصطناعي المحلي لتحليل مخططات التداول وإعطاء تحليل احترافي.",
|
58 |
+
theme="default",
|
59 |
+
examples=[["example_chart.png"]]
|
60 |
)
|
61 |
|
|
|
62 |
if __name__ == "__main__":
|
63 |
interface.launch()
|