walker11 commited on
Commit
017a7bc
·
verified ·
1 Parent(s): 4ecc48c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python
2
  import os
3
  import sys
4
  import base64
@@ -169,8 +168,8 @@ class StoryGenerator:
169
  self.site_url = os.getenv("SITE_URL", "https://rawi-kids-stories.com")
170
  self.site_name = os.getenv("SITE_NAME", "Rawi Kids Stories")
171
 
172
- # OpenRouter model for vision capabilities - Updated to use Llama Vision
173
- self.vision_model = "meta-llama/llama-3.2-11b-vision-instruct:free"
174
 
175
  # Story template for kids ages 6-10
176
  self.template = "اكتب قصة بسيطة وممتعة لطفل يتراوح عمره بين 6-10 سنوات عن: {}. حافظ على أن تكون القصة حوالي 300-400 كلمة بلغة بسيطة ورسالة إيجابية. اكتب القصة باللغة العربية الفصحى المناسبة للأطفال. تأكد من أن القصة تحترم الثقافة والأخلاق العربية والإسلامية. في نهاية القصة، اختم بعبارة واضحة تبدأ بـ 'ومن هذه القصة نتعلم أن...' توضح الدرس الإيجابي المستفاد من القصة."
@@ -200,7 +199,7 @@ class StoryGenerator:
200
  }
201
 
202
  def get_image_description(self, image_bytes):
203
- """Get a detailed description of the image using OpenRouter's Llama Vision model"""
204
  if not self.openrouter_api_key:
205
  raise ValueError("OpenRouter API key not set")
206
 
@@ -211,7 +210,7 @@ class StoryGenerator:
211
  prompt = "صف هذه الصورة بالتفصيل. ركز على العناصر الرئيسية والأعمال والإعدادات وأي عناصر ملحوظة. قدم وصفًا واضحًا وشاملًا يمكن استخدامه كسياق لكتابة قصة للأطفال. الرجاء الرد باللغة العربية."
212
 
213
  try:
214
- # Call the OpenRouter API with Llama Vision model
215
  headers = {
216
  "Content-Type": "application/json",
217
  "Authorization": f"Bearer {self.openrouter_api_key}",
@@ -332,7 +331,7 @@ class StoryGenerator:
332
  image.save(buffered, format="JPEG", quality=85)
333
  img_bytes = buffered.getvalue()
334
 
335
- # Step 1: Get image description using OpenRouter/Llama Vision
336
  description = self.get_image_description(img_bytes)
337
 
338
  # Step 2: Generate story from description using DeepSeek (with random theme)
@@ -625,4 +624,4 @@ with gr.Blocks(title="Rawi Kids Story Generator") as demo:
625
 
626
  # Launch the app
627
  if __name__ == "__main__":
628
- demo.launch()
 
 
1
  import os
2
  import sys
3
  import base64
 
168
  self.site_url = os.getenv("SITE_URL", "https://rawi-kids-stories.com")
169
  self.site_name = os.getenv("SITE_NAME", "Rawi Kids Stories")
170
 
171
+ # OpenRouter model for vision capabilities
172
+ self.vision_model = "openai/gpt-4.1"
173
 
174
  # Story template for kids ages 6-10
175
  self.template = "اكتب قصة بسيطة وممتعة لطفل يتراوح عمره بين 6-10 سنوات عن: {}. حافظ على أن تكون القصة حوالي 300-400 كلمة بلغة بسيطة ورسالة إيجابية. اكتب القصة باللغة العربية الفصحى المناسبة للأطفال. تأكد من أن القصة تحترم الثقافة والأخلاق العربية والإسلامية. في نهاية القصة، اختم بعبارة واضحة تبدأ بـ 'ومن هذه القصة نتعلم أن...' توضح الدرس الإيجابي المستفاد من القصة."
 
199
  }
200
 
201
  def get_image_description(self, image_bytes):
202
+ """Get a detailed description of the image using OpenRouter's GPT-4.1"""
203
  if not self.openrouter_api_key:
204
  raise ValueError("OpenRouter API key not set")
205
 
 
210
  prompt = "صف هذه الصورة بالتفصيل. ركز على العناصر الرئيسية والأعمال والإعدادات وأي عناصر ملحوظة. قدم وصفًا واضحًا وشاملًا يمكن استخدامه كسياق لكتابة قصة للأطفال. الرجاء الرد باللغة العربية."
211
 
212
  try:
213
+ # Call the OpenRouter API with GPT-4.1 model
214
  headers = {
215
  "Content-Type": "application/json",
216
  "Authorization": f"Bearer {self.openrouter_api_key}",
 
331
  image.save(buffered, format="JPEG", quality=85)
332
  img_bytes = buffered.getvalue()
333
 
334
+ # Step 1: Get image description using OpenRouter/GPT-4.1
335
  description = self.get_image_description(img_bytes)
336
 
337
  # Step 2: Generate story from description using DeepSeek (with random theme)
 
624
 
625
  # Launch the app
626
  if __name__ == "__main__":
627
+ demo.launch()