Spaces:
Build error
Build error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,78 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
-
|
| 4 |
-
# نموذج أقوى
|
| 5 |
-
MODEL = "google/flan-t5-xl"
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
| 7 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL)
|
| 8 |
-
|
| 9 |
-
# مولد النصوص
|
| 10 |
-
def generate_content(topic, style_choice, lang_choice, length_choice):
|
| 11 |
-
# اختيار الطول
|
| 12 |
-
if length_choice == "Short":
|
| 13 |
-
max_len = 200
|
| 14 |
-
elif length_choice == "Medium":
|
| 15 |
-
max_len = 400
|
| 16 |
-
else: # Long
|
| 17 |
-
max_len = 700
|
| 18 |
-
|
| 19 |
-
# بناء البرومبت
|
| 20 |
-
if lang_choice == "Arabic":
|
| 21 |
-
if style_choice == "Blog Post (Descriptive)":
|
| 22 |
-
prompt = f"اكتب مقالاً احترافياً بأسلوب شخصي عن: {topic}. ركز على التفاصيل والوصف الجذاب. اجعل النص منسقاً بفقرات."
|
| 23 |
-
elif style_choice == "Social Media Post (Short & Catchy)":
|
| 24 |
-
prompt = f"اكتب منشوراً قصيراً وجذاباً عن: {topic}. أضف إيموجي مناسبة واقترح 3 هاشتاغات."
|
| 25 |
-
else: # Video Script
|
| 26 |
-
prompt = f"اكتب سيناريو فيديو احترافي عن: {topic}. اجعل الأسلوب قصصي وسردي مع تقسيمه إلى مشاهد."
|
| 27 |
-
else: # English
|
| 28 |
-
if style_choice == "Blog Post (Descriptive)":
|
| 29 |
-
prompt = f"Write a professional blog post about: {topic}. Make it personal and descriptive, well-structured in paragraphs."
|
| 30 |
-
elif style_choice == "Social Media Post (Short & Catchy)":
|
| 31 |
-
prompt = f"Write a short and catchy social media post about: {topic}, add emojis and suggest 3 hashtags."
|
| 32 |
-
else: # Video Script
|
| 33 |
-
prompt = f"Write a professional video script about: {topic}. Make it emotional, story-driven, and divided into scenes."
|
| 34 |
-
|
| 35 |
-
try:
|
| 36 |
-
inputs = tokenizer(prompt, return_tensors="pt")
|
| 37 |
-
outputs = model.generate(
|
| 38 |
-
**inputs,
|
| 39 |
-
max_length=max_len,
|
| 40 |
-
num_beams=5,
|
| 41 |
-
temperature=0.8,
|
| 42 |
-
early_stopping=True
|
| 43 |
-
)
|
| 44 |
-
content = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 45 |
-
|
| 46 |
-
return content
|
| 47 |
-
except Exception as e:
|
| 48 |
-
return f"⚠️ Error: {str(e)}"
|
| 49 |
-
|
| 50 |
-
# واجهة Gradio
|
| 51 |
-
with gr.Blocks(theme="default") as iface:
|
| 52 |
-
gr.Markdown("## ✨ AI Content Pack - Create Blogs, Posts & Scripts in Seconds")
|
| 53 |
-
|
| 54 |
-
with gr.Row():
|
| 55 |
-
topic = gr.Textbox(label="Topic / الموضوع", placeholder="مثال: رحلتي إلى باريس وتجربة برج إيفل...")
|
| 56 |
-
|
| 57 |
-
with gr.Row():
|
| 58 |
-
style_choice = gr.Radio(
|
| 59 |
-
["Blog Post (Descriptive)", "Social Media Post (Short & Catchy)", "Video Script (Storytelling)"],
|
| 60 |
-
label="Style / نوع المحتوى"
|
| 61 |
-
)
|
| 62 |
-
lang_choice = gr.Radio(["Arabic", "English"], label="Language / اللغة")
|
| 63 |
-
length_choice = gr.Radio(["Short", "Medium", "Long"], label="Length / طول النص", value="Medium")
|
| 64 |
-
|
| 65 |
-
output = gr.Textbox(label="Generated Content", lines=20)
|
| 66 |
-
download_btn = gr.File(label="Download", file_types=[".txt"])
|
| 67 |
-
|
| 68 |
-
def save_file(content):
|
| 69 |
-
with open("generated.txt", "w", encoding="utf-8") as f:
|
| 70 |
-
f.write(content)
|
| 71 |
-
return "generated.txt"
|
| 72 |
-
|
| 73 |
-
btn = gr.Button("🚀 Generate Content")
|
| 74 |
-
btn.click(fn=generate_content, inputs=[topic, style_choice, lang_choice, length_choice], outputs=output)
|
| 75 |
-
output.change(fn=save_file, inputs=output, outputs=download_btn)
|
| 76 |
-
|
| 77 |
-
if __name__ == "__main__":
|
| 78 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|