Kunal08 commited on
Commit
d587f21
·
1 Parent(s): b280c3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -58
app.py CHANGED
@@ -40,58 +40,7 @@ def chatbot(input, api_key):
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="AI-generated response - Powered By OpenAi's ChatGPT")
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,import os
53
- import requests
54
- import openai
55
- import gradio as gr
56
-
57
- openai.api_key = None
58
-
59
- start_sequence = "\nAI:"
60
- restart_sequence = "\nHuman:"
61
-
62
- import json
63
-
64
- url = 'https://archive.org/download/amazon_help_prepared/amazon_help_prepared.jsonl'
65
- response = requests.get(url)
66
- data = []
67
- with open('amazon_help_prepared.jsonl', 'wb') as f:
68
- f.write(response.content)
69
- with open('amazon_help_prepared.jsonl', 'r', encoding='utf-8') as f:
70
- for line in f:
71
- data.append(json.loads(line))
72
- prompt = data
73
-
74
- def openai_creat(prompt, api_key):
75
- openai.api_key = api_key
76
- response = openai.Completion.create(
77
- model='text-davinci-003',
78
- prompt=prompt,
79
- temperature=0.9,
80
- max_tokens=400,
81
- top_p=1,
82
- frequency_penalty=0,
83
- presence_penalty=0.6,
84
- stop=[" Human:", " AI:"]
85
- )
86
- return response.choices[0].text
87
-
88
- def chatbot(input, api_key):
89
- output = openai_creat(input, api_key)
90
- return output
91
-
92
- api_key_input = gr.inputs.Textbox(label="OpenAI API Key")
93
- text_input = gr.inputs.Textbox(label="Type your question here")
94
- output_text = gr.outputs.Textbox(label="AI-generated response - Powered By OpenAi's ChatGPT")
95
 
96
  title_html = "<h2 style='text-align:center;font-weight:bold;color:black;'>Amazon Vendor Help Centre</h2>"
97
  desc_html = "<p style='text-align:center;'>Ask our AI chatbot any question related to Amazon vendor and get instant response!</p>"
@@ -105,10 +54,4 @@ chatbot_interface = gr.Interface(
105
  allow_screenshot=False
106
  )
107
 
108
- chatbot_interface.launch()
109
-
110
- description=desc_html,
111
- allow_screenshot=False
112
- )
113
-
114
  chatbot_interface.launch(debug=True)
 
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>"
 
54
  allow_screenshot=False
55
  )
56
 
 
 
 
 
 
 
57
  chatbot_interface.launch(debug=True)