Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,16 +2,14 @@ import os
|
|
2 |
import requests
|
3 |
import openai
|
4 |
import gradio as gr
|
5 |
-
import json
|
6 |
|
7 |
-
|
8 |
-
openai.api_key = None # initialize the API key as None
|
9 |
|
10 |
-
# Define conversation start and restart sequences
|
11 |
start_sequence = "\nAI:"
|
12 |
restart_sequence = "\nHuman:"
|
13 |
|
14 |
-
|
|
|
15 |
url = 'https://archive.org/download/amazon_help_prepared/amazon_help_prepared.jsonl'
|
16 |
response = requests.get(url)
|
17 |
data = []
|
@@ -22,9 +20,8 @@ with open('amazon_help_prepared.jsonl', 'r', encoding='utf-8') as f:
|
|
22 |
data.append(json.loads(line))
|
23 |
prompt = data
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
openai.api_key = api_key # set the API key
|
28 |
response = openai.Completion.create(
|
29 |
model='text-davinci-003',
|
30 |
prompt=prompt,
|
@@ -37,26 +34,24 @@ def openai_create(prompt, api_key):
|
|
37 |
)
|
38 |
return response.choices[0].text
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
output
|
43 |
-
history.append((input, output))
|
44 |
-
return history, history
|
45 |
|
46 |
-
# Set up UI inputs and outputs
|
47 |
api_key_input = gr.inputs.Textbox(label="OpenAI API Key")
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
2 |
import requests
|
3 |
import openai
|
4 |
import gradio as gr
|
|
|
5 |
|
6 |
+
openai.api_key = None
|
|
|
7 |
|
|
|
8 |
start_sequence = "\nAI:"
|
9 |
restart_sequence = "\nHuman:"
|
10 |
|
11 |
+
import json
|
12 |
+
|
13 |
url = 'https://archive.org/download/amazon_help_prepared/amazon_help_prepared.jsonl'
|
14 |
response = requests.get(url)
|
15 |
data = []
|
|
|
20 |
data.append(json.loads(line))
|
21 |
prompt = data
|
22 |
|
23 |
+
def openai_creat(prompt, api_key):
|
24 |
+
openai.api_key = api_key
|
|
|
25 |
response = openai.Completion.create(
|
26 |
model='text-davinci-003',
|
27 |
prompt=prompt,
|
|
|
34 |
)
|
35 |
return response.choices[0].text
|
36 |
|
37 |
+
def chatbot(input, api_key):
|
38 |
+
output = openai_creat(input, api_key)
|
39 |
+
return output
|
|
|
|
|
40 |
|
|
|
41 |
api_key_input = gr.inputs.Textbox(label="OpenAI API Key")
|
42 |
+
text_input = gr.inputs.Textbox(label="Type your question here")
|
43 |
+
output_text = gr.outputs.Textbox(label="Chatbot response")
|
44 |
+
|
45 |
+
title_html = "<h2 style='text-align:center;font-weight:bold;color:black;'>Amazon Vendor Help Centre</h2>"
|
46 |
+
desc_html = "<p style='text-align:center;'>Ask our AI chatbot any question related to Amazon vendor and get instant response!</p>"
|
47 |
+
|
48 |
+
chatbot_interface = gr.Interface(
|
49 |
+
fn=chatbot,
|
50 |
+
inputs=[text_input, api_key_input],
|
51 |
+
outputs=output_text,
|
52 |
+
title=title_html,
|
53 |
+
description=desc_html,
|
54 |
+
allow_screenshot=False
|
55 |
+
)
|
56 |
+
|
57 |
+
chatbot_interface.launch(debug=True)
|