rairo commited on
Commit
d2ae586
·
verified ·
1 Parent(s): ab929c6

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +3 -9
main.py CHANGED
@@ -247,11 +247,9 @@ def generate_story_endpoint():
247
  return jsonify({'error': 'Invalid or expired token'}), 401
248
 
249
  # --- Read Request Data ---
250
- # If the user is uploading a file (PDF or CSV/Excel), we can read from request.files
251
- # If the user is sending JSON only, we read request.get_json()
252
  data = request.form.to_dict() # For multipart/form-data fields
253
  input_type = data.get('input_type', 'text') # "text", "pdf", "wiki", "bible", "youtube", "dataframe"
254
- prompt = data.get('prompt') # For "text" or fallback
255
  story_type = data.get('story_type', 'free_form')
256
  style = data.get('style', 'whimsical')
257
  voice_model = data.get('voice_model', 'aura-asteria-en')
@@ -262,7 +260,6 @@ def generate_story_endpoint():
262
  if input_type not in ["text", "pdf", "wiki", "bible", "youtube", "dataframe"]:
263
  return jsonify({'error': 'Unsupported input_type'}), 400
264
 
265
- # 1) Generate the full story text
266
  from stories import generate_story_from_text
267
  from stories import get_pdf_text
268
  from stories import get_df
@@ -271,22 +268,20 @@ def generate_story_endpoint():
271
  full_story = None
272
 
273
  if input_type == "text":
 
 
274
  if not prompt:
275
  return jsonify({'error': 'Prompt is required for text input'}), 400
276
  full_story = generate_story_from_text(prompt, story_type)
277
 
278
  elif input_type == "pdf":
279
- # Expecting a file in request.files["file"]
280
  uploaded_file = request.files.get("file")
281
  if not uploaded_file:
282
  return jsonify({'error': 'No PDF file uploaded'}), 400
283
-
284
- # Convert PDF to text
285
  pdf_text = get_pdf_text(uploaded_file)
286
  full_story = generate_story_from_text(pdf_text, story_type)
287
 
288
  elif input_type == "dataframe":
289
- # Expecting a file in request.files["file"] and an "ext" field (csv, xlsx, xls)
290
  uploaded_file = request.files.get("file")
291
  ext = data.get("ext") # e.g. "csv", "xlsx", "xls"
292
  if not uploaded_file or not ext:
@@ -360,7 +355,6 @@ def generate_story_endpoint():
360
  os.remove(image_filename)
361
 
362
  # Generate audio from section text WITHOUT <image> description
363
- # e.g. remove <...> from text
364
  audio_text = re.sub(r"<.*?>", "", section_text) # remove anything in angle brackets
365
  audio_start = time.time()
366
  audio_file_path = generate_audio(audio_text, voice_model, audio_model=audio_model)
 
247
  return jsonify({'error': 'Invalid or expired token'}), 401
248
 
249
  # --- Read Request Data ---
 
 
250
  data = request.form.to_dict() # For multipart/form-data fields
251
  input_type = data.get('input_type', 'text') # "text", "pdf", "wiki", "bible", "youtube", "dataframe"
252
+ prompt = data.get('prompt') # For "text" only
253
  story_type = data.get('story_type', 'free_form')
254
  style = data.get('style', 'whimsical')
255
  voice_model = data.get('voice_model', 'aura-asteria-en')
 
260
  if input_type not in ["text", "pdf", "wiki", "bible", "youtube", "dataframe"]:
261
  return jsonify({'error': 'Unsupported input_type'}), 400
262
 
 
263
  from stories import generate_story_from_text
264
  from stories import get_pdf_text
265
  from stories import get_df
 
268
  full_story = None
269
 
270
  if input_type == "text":
271
+ # <-- CHANGE HERE
272
+ # We only check 'prompt' if input_type == "text"
273
  if not prompt:
274
  return jsonify({'error': 'Prompt is required for text input'}), 400
275
  full_story = generate_story_from_text(prompt, story_type)
276
 
277
  elif input_type == "pdf":
 
278
  uploaded_file = request.files.get("file")
279
  if not uploaded_file:
280
  return jsonify({'error': 'No PDF file uploaded'}), 400
 
 
281
  pdf_text = get_pdf_text(uploaded_file)
282
  full_story = generate_story_from_text(pdf_text, story_type)
283
 
284
  elif input_type == "dataframe":
 
285
  uploaded_file = request.files.get("file")
286
  ext = data.get("ext") # e.g. "csv", "xlsx", "xls"
287
  if not uploaded_file or not ext:
 
355
  os.remove(image_filename)
356
 
357
  # Generate audio from section text WITHOUT <image> description
 
358
  audio_text = re.sub(r"<.*?>", "", section_text) # remove anything in angle brackets
359
  audio_start = time.time()
360
  audio_file_path = generate_audio(audio_text, voice_model, audio_model=audio_model)