Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
|
| 4 |
+
# Using a powerful model for creative text generation
|
| 5 |
+
MODEL = "google/flan-t5-large"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL)
|
| 8 |
+
|
| 9 |
+
def generate_story(topic, style_choice, lang_choice):
|
| 10 |
+
# Language and style selection based on user input
|
| 11 |
+
if lang_choice == "Arabic":
|
| 12 |
+
if style_choice == "Blog Post (Descriptive)":
|
| 13 |
+
prompt = f"اكتب مقالاً مفصلاً لمدونة باللغة العربية عن: {topic}. اجعل النغمة شخصية، ووصف الأماكن والأحداث بشكل جذاب."
|
| 14 |
+
elif style_choice == "Social Media Post (Short & Catchy)":
|
| 15 |
+
prompt = f"اكتب منشوراً قصيراً وجذاباً باللغة العربية عن: {topic}، مع إيموجي وهاشتاغات مقترحة."
|
| 16 |
+
else: # Video Script (Storytelling)
|
| 17 |
+
prompt = f"اكتب سيناريو فيديو (script) باللغة العربية عن: {topic}. ركز على سرد قصة عاطفية وجذابة، مع وصف للمشاهد."
|
| 18 |
+
else: # English
|
| 19 |
+
if style_choice == "Blog Post (Descriptive)":
|
| 20 |
+
prompt = f"Write a detailed blog post in English about: {topic}. Make the tone personal, and describe the places and events attractively."
|
| 21 |
+
elif style_choice == "Social Media Post (Short & Catchy)":
|
| 22 |
+
prompt = f"Write a short and catchy social media post in English about: {topic}, with emojis and suggested hashtags."
|
| 23 |
+
else: # Video Script (Storytelling)
|
| 24 |
+
prompt = f"Write a video script (storytelling) in English about: {topic}. Focus on a personal and emotional story, with scene descriptions."
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 28 |
+
outs = model.generate(**inputs, max_length=500, num_beams=5, early_stopping=True)
|
| 29 |
+
return tokenizer.decode(outs[0], skip_special_tokens=True)
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return f"An error occurred: {str(e)}. Please make sure the topic is clearly written."
|
| 32 |
+
|
| 33 |
+
iface = gr.Interface(
|
| 34 |
+
fn=generate_story,
|
| 35 |
+
inputs=[
|
| 36 |
+
gr.Textbox(label="Topic (e.g., 'My trip to Paris, seeing the Eiffel Tower and eating croissants')"),
|
| 37 |
+
gr.Radio(["Blog Post (Descriptive)", "Social Media Post (Short & Catchy)", "Video Script (Storytelling)"], label="Style"),
|
| 38 |
+
gr.Radio(["Arabic", "English"], label="Language")
|
| 39 |
+
],
|
| 40 |
+
outputs=gr.Textbox(label="Result", lines=10)
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
iface.launch()
|