Spaces:
Sleeping
Sleeping
File size: 1,162 Bytes
a8da7ed 4bec409 7cfecec a8da7ed 4bec409 a8da7ed 4bec409 a8da7ed 4bec409 a8da7ed 4bec409 a8da7ed 4bec409 a8da7ed | 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 | import os
from docx import Document
from huggingface_hub import HfApi
def process_uploaded_file(file):
"""قراءة محتوى الملف المرفوع وتحويله إلى نص للمعالجة"""
if file is None:
return ""
file_path = file.name
if file_path.endswith('.txt'):
with open(file_path, 'r', encoding='utf-8') as f:
return f.read()
elif file_path.endswith('.docx'):
doc = Document(file_path)
return "\n".join([para.text for para in doc.paragraphs])
return ""
def export_to_docx(final_text, filename="Final_Novel_Draft.docx"):
"""تحويل مخرجات Ling-1T إلى ملف Word منسق واحترافي"""
doc = Document()
# إضافة عنوان الرواية بتنسيق مميز
title = doc.add_heading('المخطوطة النهائية للرواية', 0)
title.alignment = 1 # محاذاة للوسط
# تنظيف النص وإضافة الفقرات
paragraphs = final_text.split('\n')
for p in paragraphs:
if p.strip():
doc.add_paragraph(p)
doc.save(filename)
return filename
|