loayshabet commited on
Commit
3f3f461
·
verified ·
1 Parent(s): d062760

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -1,12 +1,10 @@
1
  import gradio as gr
2
- from transformers import AutoProcessor, AutoModelForVision2Seq
3
  from PIL import Image
4
  import io
5
 
6
- # 🔍 تحميل النموذج والمُعالِج
7
- model_id = "HuggingFaceM4/sla-v1"
8
- processor = AutoProcessor.from_pretrained(model_id)
9
- model = AutoModelForVision2Seq.from_pretrained(model_id).to("cuda" if torch.cuda.is_available() else "cpu")
10
 
11
  # 💬 تعليمات الذكاء الاصطناعي لتكون خبير تداول
12
  SYSTEM_PROMPT = """
@@ -34,14 +32,11 @@ def analyze_chart(image):
34
  # إنشاء prompt شامل
35
  text = f"Question: {SYSTEM_PROMPT}\nAnswer:"
36
 
37
- # المعالجة
38
- inputs = processor(images=img, text=text, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
39
 
40
- # التوليد
41
- generated_ids = model.generate(**inputs, max_new_tokens=256)
42
- response = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
43
-
44
- return response.strip()
45
 
46
  except Exception as e:
47
  return f"❌ حدث خطأ أثناء التحليل: {str(e)}"
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
  from PIL import Image
4
  import io
5
 
6
+ # 📦 تحميل النموذج باستخدام Pipeline
7
+ pipe = pipeline("image-to-text", model="microsoft/kosmos-2-patch14-224")
 
 
8
 
9
  # 💬 تعليمات الذكاء الاصطناعي لتكون خبير تداول
10
  SYSTEM_PROMPT = """
 
32
  # إنشاء prompt شامل
33
  text = f"Question: {SYSTEM_PROMPT}\nAnswer:"
34
 
35
+ # التحليل باستخدام Pipeline
36
+ response = pipe(img, text)
37
 
38
+ # تنظيف الإجابة
39
+ return response[0]["generated_text"]
 
 
 
40
 
41
  except Exception as e:
42
  return f"❌ حدث خطأ أثناء التحليل: {str(e)}"