Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -20,7 +20,14 @@ Output: A JSON response containing a list of questions and a corresponding list
|
|
| 20 |
|
| 21 |
app = FastAPI(docs_url="/", description=description)
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
@app.post("/get_questions")
|
| 26 |
async def getQuestions(job_description: str, no_of_questions: int):
|
|
@@ -38,5 +45,6 @@ async def getQuestions(job_description: str, no_of_questions: int):
|
|
| 38 |
result = response.choices[0].message.content
|
| 39 |
# Parse the JSON data
|
| 40 |
parsed_data = json.loads(result)
|
|
|
|
| 41 |
|
| 42 |
return parsed_data
|
|
|
|
| 20 |
|
| 21 |
app = FastAPI(docs_url="/", description=description)
|
| 22 |
|
| 23 |
+
def convert_format(input_dict):
|
| 24 |
+
output_list = []
|
| 25 |
+
for i in range(1, len(input_dict) // 2 + 1):
|
| 26 |
+
question_key = f"Question {i}"
|
| 27 |
+
answer_key = f"Answer {i}"
|
| 28 |
+
if question_key in input_dict and answer_key in input_dict:
|
| 29 |
+
output_list.append({"Question": input_dict[question_key], "Answer": input_dict[answer_key]})
|
| 30 |
+
return output_list
|
| 31 |
|
| 32 |
@app.post("/get_questions")
|
| 33 |
async def getQuestions(job_description: str, no_of_questions: int):
|
|
|
|
| 45 |
result = response.choices[0].message.content
|
| 46 |
# Parse the JSON data
|
| 47 |
parsed_data = json.loads(result)
|
| 48 |
+
parsed_data = convert_format(parsed_data)
|
| 49 |
|
| 50 |
return parsed_data
|