Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
from PIL import Image
|
| 4 |
import io
|
| 5 |
|
| 6 |
-
# 📦 تحميل ال
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
# 💬 تعليمات الذكاء الاصطناعي لتكون خبير تداول
|
| 10 |
SYSTEM_PROMPT = """
|
|
@@ -29,17 +30,21 @@ def analyze_chart(image):
|
|
| 29 |
# تحويل الصورة إلى RGB
|
| 30 |
img = image.convert("RGB")
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
|
| 35 |
-
# ال
|
| 36 |
-
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
-
return f"❌ حدث خطأ أثناء التحليل:
|
| 43 |
|
| 44 |
# 🖥️ واجهة Gradio
|
| 45 |
interface = gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoProcessor, Kosmos2ForConditionalGeneration
|
| 3 |
from PIL import Image
|
| 4 |
import io
|
| 5 |
|
| 6 |
+
# 📦 تحميل المعالج والنموذج
|
| 7 |
+
processor = AutoProcessor.from_pretrained("microsoft/kosmos-2-patch14-224")
|
| 8 |
+
model = Kosmos2ForConditionalGeneration.from_pretrained("microsoft/kosmos-2-patch14-224")
|
| 9 |
|
| 10 |
# 💬 تعليمات الذكاء الاصطناعي لتكون خبير تداول
|
| 11 |
SYSTEM_PROMPT = """
|
|
|
|
| 30 |
# تحويل الصورة إلى RGB
|
| 31 |
img = image.convert("RGB")
|
| 32 |
|
| 33 |
+
# دمج التعليمات مع الصورة
|
| 34 |
+
prompt = f"{SYSTEM_PROMPT}\nQuestion: ما هو تحليل هذه الصورة؟\nAnswer:"
|
| 35 |
|
| 36 |
+
# المعالجة
|
| 37 |
+
inputs = processor(images=img, text=prompt, return_tensors="pt")
|
| 38 |
|
| 39 |
+
# التوليد
|
| 40 |
+
generated_ids = model.generate(**inputs, max_new_tokens=256)
|
| 41 |
+
response = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
|
| 42 |
+
response = processor.tokenizer.decode(processor.tokenizer.encode(response.split("Answer:")[-1].strip()))
|
| 43 |
+
|
| 44 |
+
return response
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
+
return f"❌ حدث خطأ أثناء التحليل:\n{str(e)}"
|
| 48 |
|
| 49 |
# 🖥️ واجهة Gradio
|
| 50 |
interface = gr.Interface(
|