Letsch22 commited on
Commit
6f6ea84
·
1 Parent(s): d167996

simpler test

Browse files
Files changed (1) hide show
  1. app.py +59 -51
app.py CHANGED
@@ -1,54 +1,62 @@
1
- import os
2
  import gradio as gr
3
- import openai
4
-
5
-
6
- user_db = {
7
- os.environ["username"]: os.environ["password"],
8
- }
9
-
10
- # Assistant Creation function
11
- def create_assistant_json(uploaded_file, assistant_name, assistant_message):
12
- client = openai.OpenAI(api_key=os.environ["API_TOKEN"])
13
- # Check if a file was uploaded
14
- print(uploaded_file)
15
- df = open(uploaded_file, "rb")
16
- file = client.files.create(file=df,
17
- purpose='assistants')
18
-
19
- assistant = client.beta.assistants.create(
20
- name=assistant_name,
21
- instructions=assistant_message,
22
- model="gpt-4-0125-preview",
23
- tools=[
24
- {
25
- "type": "retrieval" # This adds the knowledge base as a tool
26
- }
27
- ],
28
- file_ids=[file.id])
 
 
 
 
 
 
 
 
 
29
 
30
- return assistant.id
31
-
32
- # Creating the Gradio interface
33
- with gr.Blocks() as demo:
34
- gr.Markdown("## To create an OpenAI Assistant please fill in the following sections. Upload a file to give the Assistant knowledge and a focus on something outside of it's normal training. Then add an assistant name and message. The Assistant message should guide the model into in a role. An example would be, You are a helpful Asssitant who is knowledgable in the field of...")
35
- gr.Markdown("## After creating the ID head to [OpenAI_Assistant_Chat](https://huggingface.co/spaces/jadend/OpenAI_Assistant_Chat).")
36
- with gr.Row():
37
- file_input = gr.File(label="Upload your file", type="filepath")
38
- assistant_name = gr.Textbox(label="The Assistant's Name")
39
- assistant_message = gr.Textbox(label="Assistant Message")
40
- generate_button = gr.Button("Generate Your Assistant ID")
41
- output_id = gr.Textbox(label="Your Asssistant ID", value="")
42
 
43
- generate_button.click(
44
- fn=create_assistant_json,
45
- inputs=[file_input, assistant_name, assistant_message],
46
- outputs=output_id
47
- )
48
-
49
- if __name__ == "__main__":
50
- demo.launch(#enable_queue=False,
51
- # Creates an auth screen
52
- auth=lambda u, p: user_db.get(u) == p,
53
- auth_message="Welcome! Enter a Username and Password"
54
- ).queue()
 
 
1
  import gradio as gr
2
+
3
+ def greet(name):
4
+ return "Hello " + name + "!!"
5
+
6
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
+ iface.launch()
8
+
9
+ # import os
10
+ # import gradio as gr
11
+ # import openai
12
+
13
+
14
+ # user_db = {
15
+ # os.environ["username"]: os.environ["password"],
16
+ # }
17
+
18
+ # # Assistant Creation function
19
+ # def create_assistant_json(uploaded_file, assistant_name, assistant_message):
20
+ # client = openai.OpenAI(api_key=os.environ["API_TOKEN"])
21
+ # # Check if a file was uploaded
22
+ # print(uploaded_file)
23
+ # df = open(uploaded_file, "rb")
24
+ # file = client.files.create(file=df,
25
+ # purpose='assistants')
26
+
27
+ # assistant = client.beta.assistants.create(
28
+ # name=assistant_name,
29
+ # instructions=assistant_message,
30
+ # model="gpt-4-0125-preview",
31
+ # tools=[
32
+ # {
33
+ # "type": "retrieval" # This adds the knowledge base as a tool
34
+ # }
35
+ # ],
36
+ # file_ids=[file.id])
37
 
38
+ # return assistant.id
39
+
40
+ # # Creating the Gradio interface
41
+ # with gr.Blocks() as demo:
42
+ # gr.Markdown("## To create an OpenAI Assistant please fill in the following sections. Upload a file to give the Assistant knowledge and a focus on something outside of it's normal training. Then add an assistant name and message. The Assistant message should guide the model into in a role. An example would be, You are a helpful Asssitant who is knowledgable in the field of...")
43
+ # gr.Markdown("## After creating the ID head to [OpenAI_Assistant_Chat](https://huggingface.co/spaces/jadend/OpenAI_Assistant_Chat).")
44
+ # with gr.Row():
45
+ # file_input = gr.File(label="Upload your file", type="filepath")
46
+ # assistant_name = gr.Textbox(label="The Assistant's Name")
47
+ # assistant_message = gr.Textbox(label="Assistant Message")
48
+ # generate_button = gr.Button("Generate Your Assistant ID")
49
+ # output_id = gr.Textbox(label="Your Asssistant ID", value="")
50
 
51
+ # generate_button.click(
52
+ # fn=create_assistant_json,
53
+ # inputs=[file_input, assistant_name, assistant_message],
54
+ # outputs=output_id
55
+ # )
56
+
57
+ # if __name__ == "__main__":
58
+ # demo.launch(#enable_queue=False,
59
+ # # Creates an auth screen
60
+ # auth=lambda u, p: user_db.get(u) == p,
61
+ # auth_message="Welcome! Enter a Username and Password"
62
+ # ).queue()