Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
#import openai
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
#if you have OpenAI API key as an environment variable, enable the below
|
6 |
+
#openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
+
|
8 |
+
#if you have OpenAI API key as a string, enable the below
|
9 |
+
#openai.api_key = "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"
|
10 |
+
os.environ["OPENAI_API_KEY"] = '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'
|
11 |
+
|
12 |
+
start_sequence = "\nAI:"
|
13 |
+
restart_sequence = "\nHuman: "
|
14 |
+
|
15 |
+
prompt = "The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.\n\nHuman: Hello, who are you?\nAI: I am an AI created by OpenAI. How can I help you today?\nHuman: "
|
16 |
+
|
17 |
+
|
18 |
+
def gradio_ask_ai(user_input):
|
19 |
+
index = GPTSimpleVectorIndex.load_from_disk('index.json')
|
20 |
+
query = user_input
|
21 |
+
response = index.query(query)
|
22 |
+
return response.response
|
23 |
+
|
24 |
+
def chatgpt_clone(input, history):
|
25 |
+
history = history or []
|
26 |
+
s = list(sum(history, ()))
|
27 |
+
s.append(input)
|
28 |
+
inp = ' '.join(s)
|
29 |
+
#output = openai_create(inp)
|
30 |
+
|
31 |
+
output = gradio_ask_ai(inp)
|
32 |
+
#print("out",type(output))
|
33 |
+
history.append((input, output))
|
34 |
+
return history, history
|
35 |
+
|
36 |
+
block = gr.Blocks()
|
37 |
+
|
38 |
+
|
39 |
+
with block:
|
40 |
+
gr.Markdown("""<h1><center>Meshworks bot</center></h1>
|
41 |
+
""")
|
42 |
+
chatbot = gr.Chatbot()
|
43 |
+
message = gr.Textbox(placeholder=prompt)
|
44 |
+
state = gr.State()
|
45 |
+
submit = gr.Button("SEND")
|
46 |
+
submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
|
47 |
+
|
48 |
+
block.launch(debug = True)
|