codelion commited on
Commit
cb99a56
·
verified ·
1 Parent(s): b37a1ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -29,15 +29,21 @@ def generate_ideas(tag):
29
  Generate a list of 5 diverse and creative ideas related to {tag} that can be used for a TikTok video.
30
  Each idea should be a short sentence describing a specific scene or concept.
31
  Return the response as a JSON object with a single key 'ideas' containing a list of 5 ideas.
 
32
  Example: {{"ideas": ["A neon-lit gaming setup with RGB lights flashing", "A futuristic robot assembling a gadget"]}}
33
  """
34
  try:
35
  response = client.models.generate_content(
36
- model='gemini-2.5-flash-preview-04-17',
37
  contents=[prompt],
38
  config=types.GenerateContentConfig(temperature=1.2)
39
  )
 
 
 
40
  response_json = json.loads(response.text.strip())
 
 
41
  return response_json['ideas']
42
  except Exception as e:
43
  print(f"Error generating ideas: {e}")
@@ -67,15 +73,21 @@ def generate_item(tag, ideas):
67
  - 'caption': A short, viral TikTok-style caption with hashtags.
68
  - 'image_prompt': A detailed image prompt for generating a high-quality visual scene.
69
  The image prompt should describe the scene vividly, specify a perspective and style, and ensure no text or letters are included.
 
70
  Example: {{"caption": "Neon vibes only! 🌌 #tech", "image_prompt": "A close-up view of a neon-lit gaming setup with RGB lights flashing, in a futuristic style, no text or letters"}}
71
  """
72
  try:
73
  response = client.models.generate_content(
74
- model='gemini-2.5-flash-preview-04-17',
75
  contents=[prompt],
76
  config=types.GenerateContentConfig(temperature=1.2)
77
  )
 
 
 
78
  response_json = json.loads(response.text.strip())
 
 
79
  text = response_json['caption']
80
  image_prompt = response_json['image_prompt']
81
  except Exception as e:
 
29
  Generate a list of 5 diverse and creative ideas related to {tag} that can be used for a TikTok video.
30
  Each idea should be a short sentence describing a specific scene or concept.
31
  Return the response as a JSON object with a single key 'ideas' containing a list of 5 ideas.
32
+ Ensure the response is strictly in JSON format.
33
  Example: {{"ideas": ["A neon-lit gaming setup with RGB lights flashing", "A futuristic robot assembling a gadget"]}}
34
  """
35
  try:
36
  response = client.models.generate_content(
37
+ model='gemini-2.0-flash', # Updated to a potentially supported model
38
  contents=[prompt],
39
  config=types.GenerateContentConfig(temperature=1.2)
40
  )
41
+ print(f"Raw response for ideas: {response.text}") # Debugging
42
+ if not response.text or response.text.isspace():
43
+ raise ValueError("Empty response from API")
44
  response_json = json.loads(response.text.strip())
45
+ if 'ideas' not in response_json or not isinstance(response_json['ideas'], list):
46
+ raise ValueError("Invalid JSON format: 'ideas' key missing or not a list")
47
  return response_json['ideas']
48
  except Exception as e:
49
  print(f"Error generating ideas: {e}")
 
73
  - 'caption': A short, viral TikTok-style caption with hashtags.
74
  - 'image_prompt': A detailed image prompt for generating a high-quality visual scene.
75
  The image prompt should describe the scene vividly, specify a perspective and style, and ensure no text or letters are included.
76
+ Ensure the response is strictly in JSON format.
77
  Example: {{"caption": "Neon vibes only! 🌌 #tech", "image_prompt": "A close-up view of a neon-lit gaming setup with RGB lights flashing, in a futuristic style, no text or letters"}}
78
  """
79
  try:
80
  response = client.models.generate_content(
81
+ model='gemini-2.0-flash', # Updated to a potentially supported model
82
  contents=[prompt],
83
  config=types.GenerateContentConfig(temperature=1.2)
84
  )
85
+ print(f"Raw response for item: {response.text}") # Debugging
86
+ if not response.text or response.text.isspace():
87
+ raise ValueError("Empty response from API")
88
  response_json = json.loads(response.text.strip())
89
+ if 'caption' not in response_json or 'image_prompt' not in response_json:
90
+ raise ValueError("Invalid JSON format: 'caption' or 'image_prompt' key missing")
91
  text = response_json['caption']
92
  image_prompt = response_json['image_prompt']
93
  except Exception as e: