File size: 2,222 Bytes
d0b3c39 1b10ef2 a9cb0b0 b56644f d0b3c39 9069208 c6f9a1b d29634e b56644f d29634e b56644f d29634e b56644f 9069208 d29634e 9069208 c6f9a1b 07a1c4f b56644f 9069208 b56644f 07a1c4f b56644f d29634e b56644f d29634e d0b3c39 a9cb0b0 d29634e 07a1c4f |
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 |
import gradio as gr
from tools.arabic_generator import ArabicTextGenerator
from tools.tool_agent import ToolCallingAgent
# Initialize models
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:
# Tab 1: Arabic Generator
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
)
# Tab 2: Tool Agent (only text generation now)
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()
|