Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from openai import OpenAI
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
OPENAI_API_KEY = os.getenv('openai')
|
6 |
+
org = os.getenv('org')
|
7 |
+
client = OpenAI(api_key=OPENAI_API_KEY, organization=org)
|
8 |
+
|
9 |
+
|
10 |
+
def getQuestions(job_description: str, no_of_questions: int):
|
11 |
+
response = client.chat.completions.create(
|
12 |
+
model="gpt-3.5-turbo-1106",
|
13 |
+
response_format={"type": "json_object"}, # To ENABLE JSON MODE
|
14 |
+
messages=[
|
15 |
+
{"role": "system",
|
16 |
+
"content": "You are a helpful assistant designed to output JSON in this format [question-text as key and its value as answer-text]"},
|
17 |
+
{"role": "user",
|
18 |
+
"content": f"Given the job description [{job_description}] create {no_of_questions} "
|
19 |
+
f"interview questions and their corresponding answers"}
|
20 |
+
]
|
21 |
+
)
|
22 |
+
result = response.choices[0].message.content
|
23 |
+
# Parse the JSON data
|
24 |
+
parsed_data = json.loads(result)
|
25 |
+
|
26 |
+
return parsed_data
|
27 |
+
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=getQuestions,
|
30 |
+
inputs=["text", "number"],
|
31 |
+
outputs="json"
|
32 |
+
)
|
33 |
+
|
34 |
+
iface.launch(auth=("orblogic", "logicorb"))
|