Mohamedh33 commited on
Commit
7cce43e
·
verified ·
1 Parent(s): 25d03f5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ from fpdf import FPDF
4
+ import PIL.Image
5
+ import uuid
6
+
7
+ # استخدم هذا الموديل لأنه سريع ومجاني تماماً
8
+ client = InferenceClient("black-forest-labs/FLUX.1-schnell")
9
+
10
+ def make_story(topic):
11
+ # 1. توليد نص القصة (استعمال موديل نصي مجاني)
12
+ text_client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
13
+ prompt = f"Write a very short 3-paragraph kids story about {topic}. Simple English."
14
+ story_text = text_client.text_generation(prompt, max_new_tokens=300)
15
+
16
+ # 2. توليد صورة الغلاف
17
+ image_prompt = f"Kids book cover illustration, cute {topic}, vibrant colors"
18
+ image = client.text_to_image(image_prompt)
19
+ img_path = f"{uuid.uuid4()}.png"
20
+ image.save(img_path)
21
+
22
+ # 3. إنشاء الـ PDF
23
+ pdf = FPDF()
24
+ pdf.add_page()
25
+ pdf.set_font("Arial", size=12)
26
+ pdf.multi_cell(0, 10, txt=story_text)
27
+ pdf.image(img_path, x=10, y=100, w=180)
28
+
29
+ pdf_path = f"story_{uuid.uuid4()}.pdf"
30
+ pdf.output(pdf_path)
31
+
32
+ return image, pdf_path
33
+
34
+ # واجهة مستخدم احترافية وسهلة للهاتف
35
+ with gr.Blocks(theme=gr.themes.Soft()) as app:
36
+ gr.Markdown("# 📚 صانع قصص الأطفال المجاني")
37
+ input_topic = gr.Textbox(label="اكتب موضوع القصة (مثلاً: قطة في الفضاء)")
38
+ btn = gr.Button("اصنع قصتي الآن ✨")
39
+
40
+ with gr.Row():
41
+ out_img = gr.Image(label="غلاف القصة")
42
+ out_pdf = gr.File(label="تحميل القصة PDF")
43
+
44
+ btn.click(make_story, inputs=input_topic, outputs=[out_img, out_pdf])
45
+
46
+ app.launch()