EngReem85 commited on
Commit
17aa29f
·
verified ·
1 Parent(s): bf4549c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -7
app.py CHANGED
@@ -35,24 +35,57 @@ def create_inspiring_line(future, value, skill):
35
  return f"⚠️ حدث خطأ أثناء التوليد: {e}"
36
 
37
  # 🎨 تصميم الواجهة
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="green", secondary_hue="teal")) as demo:
39
  gr.HTML("""
40
- <div style="display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; margin-top:20px;">
41
- <img src="https://i.imgur.com/n7yR2tE.png" alt="شعار Eng.Reem" width="130" style="border-radius:50%; box-shadow:0 0 15px rgba(0,0,0,0.1); margin-bottom:15px;">
42
- <h1 style="color:#3b5f3b; font-family:'Tajawal', sans-serif;">💫 صناع الأثر</h1>
43
- <p style="color:#4b6043; font-size:18px;">حيث تتحول الأحلام إلى ومضات من الإلهام والإبداع ✨</p>
44
  </div>
45
  """)
46
 
47
  with gr.Row():
48
  with gr.Column(scale=1):
49
  future = gr.Textbox(label=" حلمك المستقبلي", placeholder="مثلاً: أن أكون مهندسة تلهم الابتكار")
50
- value = gr.Textbox(label=" الأثر الذي تريدين تركه", placeholder=" مثلاً: تحويل الخيال لواقع ")
51
  skill = gr.Textbox(label=" مهارتك المميزة", placeholder="مثلاً: التحليل الإبداعي وحل المشكلات")
52
  submit = gr.Button("✨ أنشئي جملتك الملهمة")
53
 
54
  with gr.Column(scale=1):
55
- output = gr.Textbox(label="🌟 ومضتك الإبداعية", lines=3)
56
 
57
  submit.click(fn=create_inspiring_line, inputs=[future, value, skill], outputs=output)
58
 
@@ -63,4 +96,4 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="green", secondary_hue="teal"))
63
  """)
64
 
65
  if __name__ == "__main__":
66
- demo.launch()
 
35
  return f"⚠️ حدث خطأ أثناء التوليد: {e}"
36
 
37
  # 🎨 تصميم الواجهة
38
+ import os
39
+ import gradio as gr
40
+ from openai import OpenAI
41
+
42
+ # 🔑 المفتاح
43
+ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY", "YOUR_API_KEY"))
44
+
45
+ def create_inspiring_line(future, value, skill):
46
+ if not future or not value or not skill:
47
+ return "⚠️ رجاءً أجيبي على جميع الحقول."
48
+
49
+ prompt = f"""
50
+ اكتب جملة عربية قصيرة جدًا (لا تتجاوز 12 كلمة)،
51
+ تكون ملهمة وإبداعية، وتعبّر عن شخصية طموحة تسعى لأن تصبح {future}،
52
+ وتؤمن بـ {value}، وتمتلك مهارة {skill}.
53
+ لا تكرر الكلمات المدخلة حرفيًا، بل استخدم المعنى بطريقة فنية وملهمة.
54
+ اجعل الجملة تبدو كأنها شعار أو ومضة تحفيز تُكتب على لوحة الإلهام.
55
+ """
56
+
57
+ try:
58
+ response = client.responses.create(
59
+ model="gpt-4.1-mini",
60
+ input=prompt,
61
+ temperature=1.0,
62
+ max_output_tokens=40,
63
+ )
64
+ text = response.output[0].content[0].text.strip()
65
+ return text or "✨ لم يتم توليد جملة هذه المرة، أعيدي المحاولة."
66
+
67
+ except Exception as e:
68
+ return f"⚠️ حدث خطأ أثناء التوليد: {e}"
69
+
70
+ # 🌿 واجهة أنيقة بالشعار المربع
71
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="green", secondary_hue="teal")) as demo:
72
  gr.HTML("""
73
+ <div style="display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; margin-top:25px;">
74
+ <img src="https://i.imgur.com/n7yR2tE.png" alt="شعار Eng.Reem" width="180" height="180" style="object-fit:cover; border-radius:15px; box-shadow:0 4px 20px rgba(0,0,0,0.15); margin-bottom:15px;">
75
+ <h1 style="color:#2f5233; font-family:'Tajawal', sans-serif; font-size:30px;">💫 صناع الأثر</h1>
76
+ <p style="color:#4b6043; font-size:18px;">حيث تتحول الأحلام إلى ومضاتٍ من الإلهام والإبداع </p>
77
  </div>
78
  """)
79
 
80
  with gr.Row():
81
  with gr.Column(scale=1):
82
  future = gr.Textbox(label=" حلمك المستقبلي", placeholder="مثلاً: أن أكون مهندسة تلهم الابتكار")
83
+ value = gr.Textbox(label=" الأثر الذي تريدين تركه", placeholder="مثلاً: تمكين الإنسان بالتقنية")
84
  skill = gr.Textbox(label=" مهارتك المميزة", placeholder="مثلاً: التحليل الإبداعي وحل المشكلات")
85
  submit = gr.Button("✨ أنشئي جملتك الملهمة")
86
 
87
  with gr.Column(scale=1):
88
+ output = gr.Textbox(label=" ومضتك الإبداعية", lines=3)
89
 
90
  submit.click(fn=create_inspiring_line, inputs=[future, value, skill], outputs=output)
91
 
 
96
  """)
97
 
98
  if __name__ == "__main__":
99
+ demo.launch()