File size: 3,263 Bytes
769518f c5fd6fe 769518f ea900c3 6affd90 5e3036c 22e35c1 a0e94a1 b7b260d 6a26058 ac3ac46 dd29ec1 83eaffb 769518f 6a26058 769518f c7fa737 769518f bf4549c 6a26058 769518f 6a26058 769518f 6a26058 769518f 17aa29f bd79c31 bf4549c a0e94a1 dd15b9e 17aa29f dd15b9e bf4549c 8992a74 bf4549c 8992a74 dd15b9e 17aa29f dd15b9e bf4549c bd79c31 dd15b9e e2bf471 ac3ac46 17aa29f |
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 72 73 74 75 76 77 |
import os
import gradio as gr
from openai import OpenAI
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
logo_file = "logo.jpg"
def create_inspiring_line(future, value, skill):
if not future or not value or not skill:
return "⚠️ رجاءً أجيبي على جميع الحقول."
prompt = f"""
اكتب جملة عربية قصيرة جدًا (لا تتجاوز 12 كلمة)،
تكون ملهمة وإبداعية، وتعبّر عن شخصية طموحة تسعى لأن تصبح {future}،
وتؤمن بـ {value}، وتمتلك مهارة {skill}.
لا تكرر الكلمات المدخلة حرفيًا، بل استخدم المعنى بطريقة فنية وملهمة.
اجعل الجملة تبدو كأنها شعار أو ومضة تحفيز تُكتب على لوحة الإلهام.
"""
try:
response = client.responses.create(
model="gpt-4.1-mini",
input=prompt,
temperature=1.0,
max_output_tokens=40,
)
text = response.output[0].content[0].text.strip()
# تنظيف محتوى الرد من أي فواصل أو مقدمات
text = text.replace("•", "").replace("-", "").replace(":", "").strip()
return text or "✨ لم يتم توليد جملة هذه المرة، أعيدي المحاولة."
except Exception as e:
return f"⚠️ حدث خطأ أثناء التوليد: {e}"
# واجهة
with gr.Blocks(theme=gr.themes.Soft(primary_hue="green", secondary_hue="teal")) as demo:
gr.Image(
value=logo_file,
label=None,
show_label=False,
show_download_button=False,
interactive=False,
elem_id="logo",
height=180,
)
gr.HTML("""
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; margin-top:25px;">
<h1 style="color:#2f5233; font-family:'Tajawal', sans-serif; font-size:30px;">💫 صناع الأثر</h1>
<p style="color:#4b6043; font-size:18px;">حيث تتحول الأحلام إلى ومضاتٍ من الإلهام والإبداع </p>
</div>
""")
with gr.Row():
with gr.Column(scale=1):
future = gr.Textbox(label=" حلمك المستقبلي", placeholder="مثلاً: أن أكون مهندسة تلهم الابتكار")
value = gr.Textbox(label=" الأثر الذي تريد تركه", placeholder="مثلاً: تحويل الخيال لواقع ")
skill = gr.Textbox(label=" مهارتك المميزة", placeholder="مثلاً: التحليل الإبداعي وحل المشكلات")
submit = gr.Button("✨ أنشئ جملتك الملهمة")
with gr.Column(scale=1):
output = gr.Textbox(label=" ومضتك الإبداعية", lines=3)
submit.click(fn=create_inspiring_line, inputs=[future, value, skill], outputs=output)
gr.HTML("""
<div style="text-align:center; margin-top:30px; color:#768a6c;">
<p>© 2025 Eng. Reem Algethami | AI & Creativity </p>
</div>
""")
if __name__ == "__main__":
demo.launch()
|