import gradio as gr import math # Define the calculator logic def calculate(expression): try: # Allow safe math functions allowed_names = {k: v for k, v in math.__dict__.items() if not k.startswith("__")} allowed_names["pi"] = math.pi allowed_names["e"] = math.e result = eval(expression, {"__builtins__": {}}, allowed_names) return str(result) except Exception: return "خطأ في الإدخال" # UI Design title = "📘 الآلة الحاسبة العلمية" description = "آلة حاسبة علمية بتصميم حديث، ألوان متناسقة، واجهة احترافية جداً." footer = "عمل زيد رافع الفريح" with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="purple")) as demo: gr.Markdown(f"# {title}") gr.Markdown(description) with gr.Row(): expression_input = gr.Textbox(label="أدخل العملية الحسابية", placeholder="مثال: sin(pi/2) + 5*3", scale=3) result_output = gr.Textbox(label="النتيجة", interactive=False) calc_button = gr.Button("احسب ✨", variant="primary") calc_button.click(calculate, inputs=expression_input, outputs=result_output) gr.Markdown(f"### {footer}") # Launch interface if __name__ == "__main__": demo.launch()