File size: 1,198 Bytes
e390a9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ced9fe
e390a9f
 
 
 
 
 
 
 
 
 
 
0ced9fe
e390a9f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gradio as gr
from openai import OpenAI
import json
import os
OPENAI_API_KEY = os.getenv('openai')
org = os.getenv('org')
client = OpenAI(api_key=OPENAI_API_KEY, organization=org)


def getQuestions(job_description: str, no_of_questions: int):
    response = client.chat.completions.create(
        model="gpt-3.5-turbo-1106",
        response_format={"type": "json_object"},  # To ENABLE JSON MODE
        messages=[
            {"role": "system",
                "content": "You are a helpful assistant designed to output JSON in this format [question-text as key and its value as answer-text]"},
            {"role": "user",
             "content": f"Given the job description [{job_description}] create {no_of_questions} "
                        f"interview questions and their corresponding answers. You need to act like a domain expert and ask relevant questions to the job description only."}
        ]
    )
    result = response.choices[0].message.content
    # Parse the JSON data
    parsed_data = json.loads(result)

    return parsed_data

iface = gr.Interface(
    fn=getQuestions,
    inputs=["text", "number"],
    outputs="json")

iface.launch(auth=("orblogic", "logicorb"))