|
|
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() |
|
|
|