Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -5,18 +5,18 @@ from utils import process_uploaded_file, export_to_docx
5
  from agents_config import create_agents
6
 
7
  def run_novel_studio(uploaded_file, manual_text, oauth_token: gr.OAuthToken | None):
8
- # جلب التوكن من تسجيل الدخول أو من متغيرات البيئة
9
  user_token = oauth_token.token if oauth_token else os.getenv("HF_TOKEN")
10
 
11
  if not user_token:
12
- return "⚠️ يرجى تسجيل الدخول عبر Hugging Face أولاً للوصول إلى النماذج.", None
13
 
14
  file_content = ""
15
  if uploaded_file is not None:
16
  try:
17
  file_content = process_uploaded_file(uploaded_file)
18
  except Exception as e:
19
- return f"❌ خطأ في قراءة الملف: {str(e)}", None
20
 
21
  combined_context = f"{file_content}\n\n{manual_text}".strip()
22
 
@@ -24,7 +24,7 @@ def run_novel_studio(uploaded_file, manual_text, oauth_token: gr.OAuthToken | No
24
  return "⚠️ المحتوى المقدم غير كافٍ. يرجى رفع ملف أو كتابة مسودة.", None
25
 
26
  try:
27
- # إنشاء الوكلاء باستخدام التوكن المجلوب تلقائياً
28
  agents_dict = create_agents(user_token)
29
 
30
  assistant_agents = [
@@ -46,7 +46,7 @@ def run_novel_studio(uploaded_file, manual_text, oauth_token: gr.OAuthToken | No
46
  llm_config=agents_dict["editor"].llm_config
47
  )
48
 
49
- init_message = f"المسودة المطلوبة:\n{combined_context}"
50
 
51
  chat_result = agents_dict["editor"].initiate_chat(
52
  manager,
@@ -61,21 +61,22 @@ def run_novel_studio(uploaded_file, manual_text, oauth_token: gr.OAuthToken | No
61
  except Exception as e:
62
  return f"❌ فشل النظام في المعالجة: {str(e)}", None
63
 
 
64
  with gr.Blocks(theme=gr.themes.Soft(), title="Ling-1T Novel Studio") as demo:
65
  with gr.Sidebar():
66
- gr.Markdown("# 🖋️ التحكم")
67
- # إضافة زر تسجيل الدخول
68
- gr.LoginButton()
69
 
70
- gr.Markdown("### 📂 ملقم المسودة")
71
- file_upload = gr.File(label="ملف الرواية", file_types=[".docx", ".txt"])
72
- text_area = gr.Textbox(label="تعليمات إضافية", lines=5)
 
73
  submit_btn = gr.Button("🚀 إطلاق فريق العمل", variant="primary")
74
-
75
  with gr.Column():
76
- gr.HTML("<h1 style='text-align:center;'>Ling-1T Novel Production Studio</h1>")
77
- output_markdown = gr.Markdown(value="بانتظار بدء العمل...")
78
- download_btn = gr.File(label="تحميل المخطوطة النهائية (.docx)")
79
 
80
  # ربط الأحداث مع إرسال oauth_token تلقائياً
81
  submit_btn.click(
@@ -87,4 +88,3 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Ling-1T Novel Studio") as demo:
87
 
88
  if __name__ == "__main__":
89
  demo.launch()
90
-
 
5
  from agents_config import create_agents
6
 
7
  def run_novel_studio(uploaded_file, manual_text, oauth_token: gr.OAuthToken | None):
8
+ # جلب التوكن تلقائياً من تسجيل الدخول أو من متغيرات البيئة
9
  user_token = oauth_token.token if oauth_token else os.getenv("HF_TOKEN")
10
 
11
  if not user_token:
12
+ return "⚠️ يرجى تسجيل الدخول عبر Hugging Face أولاً للوصول إلى النماذج بصلاحياتك.", None
13
 
14
  file_content = ""
15
  if uploaded_file is not None:
16
  try:
17
  file_content = process_uploaded_file(uploaded_file)
18
  except Exception as e:
19
+ return f"❌ خطأ في قراءة ملف docx: {str(e)}", None
20
 
21
  combined_context = f"{file_content}\n\n{manual_text}".strip()
22
 
 
24
  return "⚠️ المحتوى المقدم غير كافٍ. يرجى رفع ملف أو كتابة مسودة.", None
25
 
26
  try:
27
+ # إنشاء فريق الوكلاء باستخدام التوكن الموثق
28
  agents_dict = create_agents(user_token)
29
 
30
  assistant_agents = [
 
46
  llm_config=agents_dict["editor"].llm_config
47
  )
48
 
49
+ init_message = f"المسودة المطلوبة للمعالجة:\n{combined_context}"
50
 
51
  chat_result = agents_dict["editor"].initiate_chat(
52
  manager,
 
61
  except Exception as e:
62
  return f"❌ فشل النظام في المعالجة: {str(e)}", None
63
 
64
+ # تصميم الواجهة مع دعم تسجيل الدخول
65
  with gr.Blocks(theme=gr.themes.Soft(), title="Ling-1T Novel Studio") as demo:
66
  with gr.Sidebar():
67
+ gr.Markdown("# 🔐 الوصول")
68
+ gr.LoginButton() # إضافة زر تسجيل الدخول لحل مشكلة الـ 403
 
69
 
70
+ gr.Markdown("---")
71
+ gr.Markdown("### 🛠️ المدخلات")
72
+ file_upload = gr.File(label="ارفع مسودة (.docx, .txt)", file_types=[".docx", ".txt"])
73
+ text_area = gr.Textbox(label="تعليمات إضافية", lines=6)
74
  submit_btn = gr.Button("🚀 إطلاق فريق العمل", variant="primary")
75
+
76
  with gr.Column():
77
+ gr.HTML("<h1 style='text-align:center;'>🖋️ Ling-1T Novel Studio</h1>")
78
+ output_markdown = gr.Markdown(value="ستظهر النتائج هنا بعد تسجيل الدخول وبدء المعالجة...")
79
+ download_btn = gr.File(label="تحميل المخطوطة (.docx)")
80
 
81
  # ربط الأحداث مع إرسال oauth_token تلقائياً
82
  submit_btn.click(
 
88
 
89
  if __name__ == "__main__":
90
  demo.launch()