Spaces:
Running
Running
File size: 2,409 Bytes
6ee159d 49382de 4c3edc4 49382de be76f2f 81f7613 49382de 81f7613 cb650e4 f114d79 81f7613 be76f2f 6ee159d be76f2f 6ee159d 49382de 6ee159d be76f2f 6ee159d 4c3edc4 be76f2f 81f7613 49382de 81f7613 49382de 81f7613 4c3edc4 6ee159d 4c3edc4 81f7613 49382de 81f7613 49382de 81f7613 4c3edc4 49382de be76f2f 81f7613 49382de |
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 requests
from PIL import Image
import io
import base64
# إعدادات API
OPENROUTER_API_URL = "https://openrouter.ai/api/v1/chat/completions"
OPENROUTER_API_KEY = "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" # ← استبدلها بـ API Key الخاص بك
MODEL_NAME = "Mistral: Magistral Medium 2506 (thinking)"
# تعليمات الذكاء الاصطناعي
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.
"""
# دالة تحويل الصورة إلى Data URI
def image_to_data_uri(img):
buffered = io.BytesIO()
img_format = img.format if img.format else "PNG"
img.save(buffered, format=img_format)
return "data:image/png;base64," + base64.b64encode(buffered.getvalue()).decode("utf-8")
# دالة التحليل
def analyze_chart(image):
if image is None:
return "❌ لم يتم تحميل أي صورة."
try:
data_uri = image_to_data_uri(image)
response = requests.post(
OPENROUTER_API_URL,
headers={
"Authorization": f"Bearer {OPENROUTER_API_KEY}",
"Content-Type": "application/json"
},
json={
"model": MODEL_NAME,
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": SYSTEM_PROMPT},
{"type": "image_url", "image_url": {"url": data_uri}}
]
}
],
"max_tokens": 512
}
)
result = response.json()
return result["choices"][0]["message"]["content"]
except Exception as e:
return f"❌ خطأ: {str(e)}"
# واجهة Gradio
interface = gr.Interface(fn=analyze_chart, inputs=gr.Image(type="pil"), outputs="markdown")
interface.launch() |