| import gradio as gr |
| from tools.arabic_generator import ArabicTextGenerator |
| from tools.tool_agent import ToolCallingAgent |
|
|
| |
| text_gen = ArabicTextGenerator() |
| tool_agent = ToolCallingAgent() |
|
|
| TOOLS = [ |
| { |
| "name": "generate_text", |
| "description": "Generate Arabic text", |
| "parameters": { |
| "prompt": {"type": "string"}, |
| "length": {"type": "integer", "max": 150} |
| } |
| } |
| ] |
|
|
| def format_output(result): |
| return str(result) |
|
|
| with gr.Blocks(title="الأدوات العربية") as app: |
| |
| with gr.Tab("🖊️ مولد النصوص"): |
| with gr.Row(): |
| with gr.Column(): |
| arabic_input = gr.Textbox(label="النص الأولي") |
| length_slider = gr.Slider(50, 300, value=100, label="طول النص") |
| generate_btn = gr.Button("توليد") |
| arabic_output = gr.Textbox(label="النص المولد", lines=10) |
| |
| generate_btn.click( |
| text_gen.generate, |
| inputs=[arabic_input, length_slider], |
| outputs=arabic_output |
| ) |
|
|
| |
| with gr.Tab("🛠️ مساعد ذكي"): |
| with gr.Row(): |
| with gr.Column(): |
| tool_input = gr.Textbox(label="اكتب طلبك هنا") |
| run_btn = gr.Button("تشغيل") |
| tool_output = gr.Textbox(label="النتيجة", lines=10) |
| |
| def process_tool(input_text): |
| try: |
| tool_call = tool_agent.generate(input_text, TOOLS) |
| if tool_call["tool_name"] == "generate_text": |
| return text_gen.generate( |
| tool_call["parameters"]["prompt"], |
| tool_call["parameters"]["length"] |
| ) |
| return "لم يتم التعرف على الأداة" |
| except Exception as e: |
| return f"خطأ: {str(e)}" |
| |
| run_btn.click( |
| lambda x: format_output(process_tool(x)), |
| inputs=tool_input, |
| outputs=tool_output |
| ) |
|
|
| if __name__ == "__main__": |
| app.launch() |
|
|