import gradio as gr import autogen from utils import process_uploaded_file, export_to_docx from agents_config import create_agents def run_novel_studio(uploaded_file, manual_text, user_token): if not user_token: return "⚠️ يرجى إدخال التوكن.", None # معالجة النص من الملف أو الكتابة اليدوية context = "" if uploaded_file is not None: context = process_uploaded_file(uploaded_file) context += "\n" + manual_text if len(context.strip()) < 10: return "⚠️ المحتوى فارغ جداً.", None try: agents = create_agents(user_token) # إعداد المجموعة groupchat = autogen.GroupChat( agents=[v for k, v in agents.items() if k != "editor"], messages=[], max_round=10 ) manager = autogen.GroupChatManager( groupchat=groupchat, llm_config=agents["editor"].llm_config ) # بدء الحوار chat_result = agents["editor"].initiate_chat( manager, message=f"أكمل هذه الرواية ونسقها:\n\n{context}" ) # استخراج النتيجة final_text = chat_result.chat_history[-1]['content'] file_path = export_to_docx(final_text) return final_text, file_path except Exception as e: return f"❌ خطأ: {str(e)}", None # واجهة بسيطة ومستقرة with gr.Blocks() as demo: gr.HTML("

👑 Ling-1T Novel Studio

") with gr.Row(): with gr.Column(): token = gr.Textbox(label="HF Token", type="password") # حددنا الأنواع بشكل صريح لضمان الاستقرار file_in = gr.File(label="Upload docx/txt") text_in = gr.Textbox(label="Manual Input", lines=5) btn = gr.Button("🚀 Start Production") with gr.Column(): text_out = gr.Textbox(label="Final Manuscript", lines=15) file_out = gr.File(label="Download DOCX") btn.click(run_novel_studio, [file_in, text_in, token], [text_out, file_out]) demo.launch()