Spaces:
Runtime error
Runtime error
File size: 3,317 Bytes
5688ac0 a224c19 3a2c805 5688ac0 dd5f53b 5688ac0 8bb1fbe caf7e7b 8bb1fbe 5688ac0 e56d75c 5688ac0 447714a 5688ac0 447714a 5688ac0 2c88269 5688ac0 8ccc2c2 8bb1fbe 5688ac0 e56d75c 8bb1fbe 0be5664 b13705c 8ccc2c2 0be5664 8bb1fbe 5688ac0 03a3aca 0be5664 5688ac0 b13705c 8ccc2c2 706709b 5688ac0 b933c3e 34d2239 b1d8648 8ccc2c2 34d2239 b1d8648 34d2239 faffd48 b1d8648 faffd48 b1d8648 b933c3e b13705c 8ccc2c2 5688ac0 f1a8b69 e0a474a b1d8648 34d2239 5688ac0 de6270a 5688ac0 e56d75c a4c5335 91bcddb 663e3fb e56d75c 8bb1fbe a4c5335 e56d75c a4c5335 e56d75c 5688ac0 e56d75c a4c5335 |
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
from openai import OpenAI
import os
import gradio as gr
import time
# Define the dropdown options
dropdown_options = ["1_BRD_Lending_v0.1.pdf", "2_BRD_Lending_v0.1.pdf", "3_BRD_Payments_v0.1.pdf"]
query = {
dropdown_options[0] : "Generate test cases for the following process: Loan Boarding Process, Loan Repayment Management, Loan Servicing Management, Disbursement Cancellation",
dropdown_options[1] : "Generate test cases for the following process: Process Flows, Quick Data Entry, RBI Defaulters, Credit Approval Process",
dropdown_options[2] : "Generate test cases for the following process: Fund Transfer and Payments, SBM Account Payment, FCY Payment , Credit Card Payment",
}
class Assistant:
def __init__(self, path):
self.client = OpenAI()
print(str(path))
# Upload a file with an "assistants" purpose
self.file = self.client.files.create(
file=open(str(path), "rb"),
purpose='assistants'
)
# Add the file to the assistant
self.assistant = self.client.beta.assistants.create(
instructions="You are an helpful assistant to generating test scenarios and test cases for test design process automation.",
model="gpt-4-1106-preview",
tools=[{"type": "retrieval"}],
file_ids=[self.file.id]
)
self.thread = self.client.beta.threads.create()
self.query = query.get(path)
def infer(self):
message = self.client.beta.threads.messages.create(
thread_id=self.thread.id,
role="user",
content=self.query,
)
# print(message)
run = self.client.beta.threads.runs.create(
thread_id = self.thread.id,
assistant_id= self.assistant.id
)
while True:
retreive = self.client.beta.threads.runs.retrieve(
thread_id = self.thread.id,
run_id= run.id
)
print(retreive.status)
if retreive.status=="completed":
break
else:
time.sleep(1)
continue
# time.sleep(1)
# run = self.client.beta.threads.runs.retrieve(
# thread_id = thread.id,
# run_id= run.id
# )
messages = self.client.beta.threads.messages.list(
thread_id =self.thread.id
)
print(messages)
for message in messages.data:
print(message.content[0].text.value)
return message.content[0].text.value
if __name__ == "__main__":
# Define a function that takes the selected option as an argument
def create_assistant(path):
obj = Assistant(path)
return obj.infer()
demo_2 = gr.Interface(
create_assistant,
[gr.Dropdown(dropdown_options, label="path", info="Select BRDS doc"),],
"text",
)
# # Create the Gradio interface with a dropdown
# iface = gr.Interface(
# fn=create_assistant(inputs),
# inputs=gr.Dropdown(choices=dropdown_options, label="Select an option"),
# outputs="text"
# )
# gr.Dropdown(
# dropdown_options, label="Animal", info="Will add more animals later!"
# ),
# Launch the interface
print("Running main")
# demo = gr.Interface(fn=obj.infer, inputs="text", outputs="text")
demo_2.launch(show_api=False, share=True) |