Kunal08's picture
Update app.py
b0b812a
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)