File size: 1,926 Bytes
72955fc
 
 
 
 
62a9edf
72955fc
 
 
 
62a9edf
 
72955fc
 
 
 
 
 
 
 
 
 
62a9edf
 
72955fc
 
 
 
 
 
 
 
 
 
 
 
62a9edf
 
 
72955fc
 
62a9edf
1a87dd8
62a9edf
 
98387f4
b0b812a
98387f4
62a9edf
 
 
 
 
 
 
 
 
 
 
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
import os
import requests
import openai
import gradio as gr

openai.api_key = None

start_sequence = "\nAI:"
restart_sequence = "\nHuman:"

import json

url = 'https://archive.org/download/amazon_help_prepared/amazon_help_prepared.jsonl'
response = requests.get(url)
data = []
with open('amazon_help_prepared.jsonl', 'wb') as f:
    f.write(response.content)
with open('amazon_help_prepared.jsonl', 'r', encoding='utf-8') as f:
    for line in f:
        data.append(json.loads(line))
prompt = data

def openai_creat(prompt, api_key):
    openai.api_key = api_key
    response = openai.Completion.create(
        model='text-davinci-003',
        prompt=prompt,
        temperature=0.9,
        max_tokens=400,
        top_p=1,
        frequency_penalty=0,
        presence_penalty=0.6,
        stop=[" Human:", " AI:"]
    ) 
    return response.choices[0].text

def chatbot(input, api_key):
    output = openai_creat(input, api_key)
    return output

api_key_input = gr.inputs.Textbox(label="OpenAI API Key")
text_input = gr.inputs.Textbox(label="Type your question here")
output_text = gr.outputs.Textbox(label="AI-generated response-Powered By OpenAi's ChatGPT")

title_html = "<h2 style='text-align:center;font-weight:bold;color:black;'>Amazon Vendor Help Centre</h2>"
#desc_html = "<p style='text-align:center;'>Ask our AI chatbot any question related to Amazon vendor and get instant response!</p>"
desc_html = "<p style='text-align:center;'>Get instant responses to any question related to Amazon vendor by asking our AI chatbot, and don't forget to share your valuable feedback with us at <a href='https://forms.gle/NLjuAi7kdLZkV1Uz7'>https://forms.gle/NLjuAi7kdLZkV1Uz7</a></p>"


chatbot_interface = gr.Interface(
    fn=chatbot, 
    inputs=[text_input, api_key_input], 
    outputs=output_text, 
    title=title_html,
    description=desc_html,
    allow_screenshot=False
)

chatbot_interface.launch(debug=True)