Spaces:
Runtime error
Runtime error
Download app.py from Mohamedh33/Atfalg: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/spaces/Mohamedh33/Atfalg/resolve/main/app.py
- Command line
-
hf download hf://spaces/Mohamedh33/Atfalg/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Mohamedh33/Atfalg/resolve/main/app.py
1.71 kB
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| from fpdf import FPDF | |
| import PIL.Image | |
| import uuid | |
| # استخدم هذا الموديل لأنه سريع ومجاني تماماً | |
| client = InferenceClient("black-forest-labs/FLUX.1-schnell") | |
| def make_story(topic): | |
| # 1. توليد نص القصة (استعمال موديل نصي مجاني) | |
| text_client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct") | |
| prompt = f"Write a very short 3-paragraph kids story about {topic}. Simple English." | |
| story_text = text_client.text_generation(prompt, max_new_tokens=300) | |
| # 2. توليد صورة الغلاف | |
| image_prompt = f"Kids book cover illustration, cute {topic}, vibrant colors" | |
| image = client.text_to_image(image_prompt) | |
| img_path = f"{uuid.uuid4()}.png" | |
| image.save(img_path) | |
| # 3. إنشاء الـ PDF | |
| pdf = FPDF() | |
| pdf.add_page() | |
| pdf.set_font("Arial", size=12) | |
| pdf.multi_cell(0, 10, txt=story_text) | |
| pdf.image(img_path, x=10, y=100, w=180) | |
| pdf_path = f"story_{uuid.uuid4()}.pdf" | |
| pdf.output(pdf_path) | |
| return image, pdf_path | |
| # واجهة مستخدم احترافية وسهلة للهاتف | |
| with gr.Blocks(theme=gr.themes.Soft()) as app: | |
| gr.Markdown("# 📚 صانع قصص الأطفال المجاني") | |
| input_topic = gr.Textbox(label="اكتب موضوع القصة (مثلاً: قطة في الفضاء)") | |
| btn = gr.Button("اصنع قصتي الآن ✨") | |
| with gr.Row(): | |
| out_img = gr.Image(label="غلاف القصة") | |
| out_pdf = gr.File(label="تحميل القصة PDF") | |
| btn.click(make_story, inputs=input_topic, outputs=[out_img, out_pdf]) | |
| app.launch() | |