Omkar008 commited on
Commit
124eddf
·
verified ·
1 Parent(s): a0ab59b

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -26
main.py CHANGED
@@ -23,19 +23,18 @@ async def batch_processing_result(request: Request, background_tasks: Background
23
  batch_id = body.get('batch_job_id')
24
  print(batch_id)
25
  # Add the processing task to background tasks
26
- # if batch_job.status == 'completed':
27
- # background_tasks.add_task(process_batch_data, batch_id)
28
- # return {"batch_job_status":'completed'}
29
-
30
- # Immediately return success response
31
- # return {'batch_job_status':'notcompleted'}
32
- insert_response = (supabase.table("batch_processing_details")
33
  .update({
34
  "batch_job_status": True,
35
  })
36
  .eq('batch_job_id',batch_id)
37
  .execute()
38
  )
 
 
 
39
 
40
  return {'batch_job_status':'completed'}
41
 
@@ -57,28 +56,24 @@ async def process_batch_data(batch_id: str):
57
  res.append(json_dict)
58
  except json.JSONDecodeError as e:
59
  print(f"Error decoding JSON on line: {line}\nError: {e}")
60
-
 
61
  for resp in res:
62
- id = resp.get('custom_id')
63
- res_id = id.split('-')[1]
 
 
64
  output = json.loads(resp.get('response').get('body').get('choices')[0].get('message').get('content'))
 
 
 
 
65
 
66
- categories = str(output.get('categories'))
67
- summary = str(output.get('summary'))
68
-
69
- supabase_resp = supabase.table("imdb_dataset").select("Description").eq("imdb_id", res_id).execute()
70
- description = supabase_resp.data[0].get('Description')
71
-
72
- insert_response = (
73
- supabase.table("imdb_outputs")
74
- .insert({
75
- "id": res_id,
76
- "description": description,
77
- 'categories': categories,
78
- 'summary': summary
79
- })
80
- .execute()
81
- )
82
  print(f"Inserted data for ID: {res_id}")
83
 
84
  except Exception as e:
 
23
  batch_id = body.get('batch_job_id')
24
  print(batch_id)
25
  # Add the processing task to background tasks
26
+ if batch_job.status == 'completed':
27
+ background_tasks.add_task(process_batch_data, batch_id)
28
+ insert_response = (supabase.table("batch_processing_details")
 
 
 
 
29
  .update({
30
  "batch_job_status": True,
31
  })
32
  .eq('batch_job_id',batch_id)
33
  .execute()
34
  )
35
+ return {"batch_job_status":'completed'}
36
+
37
+
38
 
39
  return {'batch_job_status':'completed'}
40
 
 
56
  res.append(json_dict)
57
  except json.JSONDecodeError as e:
58
  print(f"Error decoding JSON on line: {line}\nError: {e}")
59
+
60
+ supa_data = []
61
  for resp in res:
62
+ id = resp.get('custom_id').split('-')
63
+ message_id = id[0]
64
+ user_id = id[1]
65
+ email = id[2]
66
  output = json.loads(resp.get('response').get('body').get('choices')[0].get('message').get('content'))
67
+ supa_data.append(output)
68
+
69
+ print("Printing the the data")
70
+ print(supa_data)
71
 
72
+ # insert_response = (
73
+ # supabase.table("imdb_outputs")
74
+ # .insert()
75
+ # .execute()
76
+ # )
 
 
 
 
 
 
 
 
 
 
 
77
  print(f"Inserted data for ID: {res_id}")
78
 
79
  except Exception as e: