import gradio as gr from github_utils import clone_repo, push_translated_files, clean_local_repo from markdown_utils import parse_markdown_files, extract_translatable_text, save_translated_files from translation_utils import translate_content def translate(repo_url, target_language): try: # 1. استيراد الملفات من GitHub files = clone_repo(repo_url) # 2. تقسيم النصوص إلى توكنات parsed_files = parse_markdown_files(files) # 3. الترجمة باستخدام نموذج اللغة translated_files = [] for file in parsed_files: translatable_texts = extract_translatable_text(file['content']) translated_content = translate_content(translatable_texts, target_language) translated_files.append({'filename': file['filename'], 'content': translated_content}) # 4. تجميع النصوص المترجمة save_translated_files(translated_files) # 5. رفع الملفات المترجمة إلى GitHub push_translated_files('cloned_repo') # 6. مسح الملفات المحلية clean_local_repo() return 'Translation completed and files pushed to GitHub' except Exception as e: return str(e) # إنشاء واجهة Gradio iface = gr.Interface( fn=translate, inputs=[gr.Textbox(label="GitHub Repo URL"), gr.Textbox(label="Target Language")], outputs="text", title="Markdown Translator", description="Translate Markdown files from a GitHub repository to a target language." ) if __name__ == "__main__": iface.launch()