EngReem85 commited on
Commit
592b5df
·
verified ·
1 Parent(s): e83e2ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -149
app.py CHANGED
@@ -1,101 +1,45 @@
1
  import os
2
  import gradio as gr
 
3
 
4
- # =============================================
5
- # توليد الجمل الملهمة (بدون API)
6
- # =============================================
 
7
 
8
  def create_inspiring_line(future, value, skill):
9
  if not future or not value or not skill:
10
  return "⚠️ رجاءً أجيبي على جميع الحقول."
11
-
12
- # أنماط متعددة للجمل الملهمة
13
- styles = [
14
- f"من {value} تولد {future}، وبمهارة {skill} ترتقين إلى القمة",
15
- f"كوني أنتِ من يجمع بين {value} و{skill} ليصنع {future} استثنائياً",
16
- f"في {future} الحقيقي، تجدين {value} كبوصلة و{skill} كجناحين",
17
- f"بين {future} و{value} يكمن سر {skill}، وهذا هو التميز",
18
- f"{future} يبدأ بـ {value} ويكتمل بـ {skill}، لتتركي أثراً لا يُنسى",
19
- f"قوة {future} تكمن في {value}، ومهارة {skill} تجعله حقيقة",
20
- f"رحلة {future} تحتاج {value} كوقود و{skill} كخريطة طريق",
21
- f"{future} هي حلمك، {value} هي رسالتك، {skill} هي إنجازك",
22
- f"بـ {value} و{skill} تستطيعين تحويل {future} إلى واقع ملموس",
23
- f"امتلاك {skill} مع الإيمان بـ {value} يصنع {future} لا يُقاوم",
24
- f"مستقبلك {future} يبنى على {value} وينمو بـ {skill}",
25
- f"أنتِ مزيج من {value} و{skill}، وهذا هو طريقك إلى {future}"
26
- ]
27
-
28
- decorations = ["✨", "💫", "🌟", "⭐", "🔥", "💡", "🎯", "🌱"]
29
-
30
- import random
31
- chosen_style = random.choice(styles)
32
- chosen_decoration = random.choice(decorations)
33
-
34
- return f"{chosen_decoration} {chosen_style}"
35
-
36
-
37
- # =============================================
38
- # واجهة Gradio (RTL - من اليمين لليسار)
39
- # =============================================
40
 
41
- with gr.Blocks(
42
- theme=gr.themes.Soft(primary_hue="green", secondary_hue="teal"),
43
- css="""
44
- /* جعل كل النصوص من اليمين لليسار */
45
- * {
46
- direction: rtl !important;
47
- text-align: right !important;
48
- }
49
-
50
- /* تنسيق الـ Textbox */
51
- .gr-textbox {
52
- direction: rtl !important;
53
- text-align: right !important;
54
- }
55
-
56
- .gr-textbox textarea {
57
- direction: rtl !important;
58
- text-align: right !important;
59
- }
60
-
61
- /* تنسيق الـ Label */
62
- label {
63
- text-align: right !important;
64
- display: block !important;
65
- width: 100% !important;
66
- }
67
-
68
- /* تنسيق الأزرار */
69
- .gr-button {
70
- direction: rtl !important;
71
- }
72
-
73
- /* تنسيق الأمثلة */
74
- .gr-examples {
75
- direction: rtl !important;
76
- }
77
-
78
- /* تنسيق الـ Container */
79
- .gradio-container {
80
- direction: rtl !important;
81
- }
82
-
83
- /* تنسيق الـ Row */
84
- .gr-row {
85
- direction: rtl !important;
86
- }
87
-
88
- /* تنسيق الـ Column */
89
- .gr-column {
90
- direction: rtl !important;
91
- }
92
  """
93
- ) as demo:
94
-
95
- # ===== الشعار =====
96
  try:
97
- gr.Image(
98
- value="logo.jpg",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  label=None,
100
  show_label=False,
101
  show_download_button=False,
@@ -103,78 +47,30 @@ with gr.Blocks(
103
  elem_id="logo",
104
  height=180,
105
  )
106
- except:
107
- pass
108
-
109
- # ===== الهيدر =====
110
  gr.HTML("""
111
  <div style="display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; margin-top:25px;">
112
- <h1 style="color:#2f5233; font-family:'Tajawal', sans-serif; font-size:30px; text-align:center;">💫 صناع الأثر</h1>
113
- <p style="color:#4b6043; font-size:18px; text-align:center;">حيث تتحول الأحلام إلى ومضاتٍ من الإلهام والإبداع</p>
114
  </div>
115
  """)
116
-
117
- # ===== المحتوى الرئيسي =====
118
  with gr.Row():
119
  with gr.Column(scale=1):
120
- future = gr.Textbox(
121
- label="🌱 حلمك المستقبلي",
122
- placeholder="مثلاً: أن أكون مهندسة تلهم الابتكار",
123
- lines=2,
124
- elem_id="future_input"
125
- )
126
- value = gr.Textbox(
127
- label="💎 الأثر الذي تريد تركه",
128
- placeholder="مثلاً: تحويل الخيال لواقع",
129
- lines=2,
130
- elem_id="value_input"
131
- )
132
- skill = gr.Textbox(
133
- label="🚀 مهارتك المميزة",
134
- placeholder="مثلاً: التحليل الإبداعي وحل المشكلات",
135
- lines=2,
136
- elem_id="skill_input"
137
- )
138
- submit = gr.Button("✨ أنشئ جملتك الملهمة", variant="primary", size="lg")
139
 
140
  with gr.Column(scale=1):
141
- output = gr.Textbox(
142
- label="💫 ومضتك الإبداعية",
143
- lines=5,
144
- placeholder="ستظهر هنا جملتك الملهمة...",
145
- show_copy_button=True,
146
- elem_id="output_box"
147
- )
148
-
149
- # ===== أمثلة سريعة =====
150
- gr.Markdown("### 📝 أمثلة لتجربتها:")
151
-
152
- gr.Examples(
153
- examples=[
154
- ["أكون مهندسة تلهم الابتكار", "تحويل الخيال لواقع", "التحليل الإبداعي وحل المشكلات"],
155
- ["أكون طبيبة مبدعة", "إنقاذ الأرواح", "التشخيص الدقيق"],
156
- ["أكون معلمة ملهمة", "بناء الأجيال", "التواصل الفعال"],
157
- ["أكون رائدة أعمال", "تغيير المجتمع", "القيادة والابتكار"],
158
- ],
159
- inputs=[future, value, skill],
160
- outputs=output,
161
- fn=create_inspiring_line,
162
- label=""
163
- )
164
-
165
- # ===== الفوتر =====
166
  gr.HTML("""
167
  <div style="text-align:center; margin-top:30px; color:#768a6c;">
168
- <p>© 2025 Eng. Reem Algethami | AI & Creativity</p>
169
  </div>
170
  """)
171
-
172
- # ===== ربط الزر بالدالة =====
173
- submit.click(fn=create_inspiring_line, inputs=[future, value, skill], outputs=output)
174
-
175
 
176
  if __name__ == "__main__":
177
- demo.launch(
178
- server_name="0.0.0.0",
179
- server_port=7860
180
- )
 
1
  import os
2
  import gradio as gr
3
+ from openai import OpenAI
4
 
5
+
6
+ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
7
+
8
+ logo_file = "logo.jpg"
9
 
10
  def create_inspiring_line(future, value, skill):
11
  if not future or not value or not skill:
12
  return "⚠️ رجاءً أجيبي على جميع الحقول."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ prompt = f"""
15
+ اكتب جملة عربية قصيرة جدًا (لا تتجاوز 12 كلمة)،
16
+ تكون ملهمة وإبداعية، وتعبّر عن شخصية طموحة تسعى لأن تصبح {future}،
17
+ وتؤمن بـ {value}، وتمتلك مهارة {skill}.
18
+ لا تكرر الكلمات المدخلة حرفيًا، بل استخدم المعنى بطريقة فنية وملهمة.
19
+ اجعل الجملة تبدو كأنها شعار أو ومضة تحفيز تُكتب على لوحة الإلهام.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  """
21
+
 
 
22
  try:
23
+ response = client.responses.create(
24
+ model="gpt-4.1-mini",
25
+ input=prompt,
26
+ temperature=1.0,
27
+ max_output_tokens=40,
28
+ )
29
+
30
+ text = response.output[0].content[0].text.strip()
31
+ # تنظيف محتوى الرد من أي فواصل أو مقدمات
32
+ text = text.replace("•", "").replace("-", "").replace(":", "").strip()
33
+ return text or "✨ لم يتم توليد جملة هذه المرة، أعيدي المحاولة."
34
+
35
+ except Exception as e:
36
+ return f"⚠️ حدث خطأ أثناء التوليد: {e}"
37
+
38
+
39
+ # واجهة
40
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="green", secondary_hue="teal")) as demo:
41
+ gr.Image(
42
+ value=logo_file,
43
  label=None,
44
  show_label=False,
45
  show_download_button=False,
 
47
  elem_id="logo",
48
  height=180,
49
  )
 
 
 
 
50
  gr.HTML("""
51
  <div style="display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; margin-top:25px;">
52
+ <h1 style="color:#2f5233; font-family:'Tajawal', sans-serif; font-size:30px;">💫 صناع الأثر</h1>
53
+ <p style="color:#4b6043; font-size:18px;">حيث تتحول الأحلام إلى ومضاتٍ من الإلهام والإبداع </p>
54
  </div>
55
  """)
56
+
 
57
  with gr.Row():
58
  with gr.Column(scale=1):
59
+ future = gr.Textbox(label=" حلمك المستقبلي", placeholder="مثلاً: أن أكون مهندسة تلهم الابتكار")
60
+ value = gr.Textbox(label=" الأثر الذي تريد تركه", placeholder="مثلاً: تحويل الخيال لواقع ")
61
+ skill = gr.Textbox(label=" مهارتك المميزة", placeholder="مثلاً: التحليل الإبداعي وحل المشكلات")
62
+ submit = gr.Button("✨ أنشئ جملتك الملهمة")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  with gr.Column(scale=1):
65
+ output = gr.Textbox(label=" ومضتك الإبداعية", lines=3)
66
+
67
+ submit.click(fn=create_inspiring_line, inputs=[future, value, skill], outputs=output)
68
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  gr.HTML("""
70
  <div style="text-align:center; margin-top:30px; color:#768a6c;">
71
+ <p>© 2025 Eng. Reem Algethami | AI & Creativity </p>
72
  </div>
73
  """)
 
 
 
 
74
 
75
  if __name__ == "__main__":
76
+ demo.launch()