Spaces:
Sleeping
Sleeping
Create. app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
|
| 4 |
+
# Using a robust and stable model for the free tier
|
| 5 |
+
MODEL = "google/flan-t5-large"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL)
|
| 8 |
+
|
| 9 |
+
def generate_content(topic, lang_choice, content_type):
|
| 10 |
+
# Language selection based on user input
|
| 11 |
+
if lang_choice == "Arabic":
|
| 12 |
+
if content_type == "YouTube Script":
|
| 13 |
+
prompt = f"اكتب سكربت يوتيوب احترافي باللغة العربية عن: {topic}. اجعله دقيقة واحدة مع مقدمة جذابة ونقاط أساسية وخاتمة."
|
| 14 |
+
elif content_type == "YouTube Title":
|
| 15 |
+
prompt = f"أنشئ عنوان يوتيوب جذاب قصير لا يتجاوز 60 حرفاً عن: {topic}."
|
| 16 |
+
elif content_type == "Description + SEO":
|
| 17 |
+
prompt = f"اكتب وصف يوتيوب مُحسَّن للسيو عن: {topic} مع هاشتاغات مقترحة."
|
| 18 |
+
else: # LinkedIn Post
|
| 19 |
+
prompt = f"اكتب منشور لينكدإن احترافي قصير بالعربية عن: {topic}."
|
| 20 |
+
else: # English
|
| 21 |
+
if content_type == "YouTube Script":
|
| 22 |
+
prompt = f"Write a professional YouTube script in English about: {topic}. Make it one minute long with an engaging intro, key points, and a conclusion."
|
| 23 |
+
elif content_type == "YouTube Title":
|
| 24 |
+
prompt = f"Create a catchy YouTube title in English, under 60 characters, about: {topic}."
|
| 25 |
+
elif content_type == "Description + SEO":
|
| 26 |
+
prompt = f"Write an SEO-friendly YouTube description about: {topic} with suggested hashtags."
|
| 27 |
+
else: # LinkedIn Post
|
| 28 |
+
prompt = f"Write a professional LinkedIn post in English about: {topic}."
|
| 29 |
+
|
| 30 |
+
# Using try-except block to handle potential model errors
|
| 31 |
+
try:
|
| 32 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 33 |
+
outs = model.generate(**inputs, max_length=300)
|
| 34 |
+
return tokenizer.decode(outs[0], skip_special_tokens=True)
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"حدث خطأ: {str(e)}. حاول مرة أخرى أو غيّر الموضوع."
|
| 37 |
+
|
| 38 |
+
iface = gr.Interface(
|
| 39 |
+
fn=generate_content,
|
| 40 |
+
inputs=[
|
| 41 |
+
gr.Textbox(label="Topic"),
|
| 42 |
+
gr.Radio(["Arabic", "English"], label="Language"),
|
| 43 |
+
gr.Radio(["YouTube Script", "YouTube Title", "Description + SEO", "LinkedIn Post"], label="Content Type")
|
| 44 |
+
],
|
| 45 |
+
outputs=gr.Textbox(label="Result")
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
iface.launch()
|