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