|
|
|
"""CKD-Gradio1.ipynb |
|
|
|
Automatically generated by Colaboratory. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/1Iy_x9Rvc62uZ-G5gQNejVwypnWFtMPkz |
|
|
|
# Step 1: Install the required libraries for the chatbot to function |
|
""" |
|
|
|
!pip install gradio |
|
|
|
!pip install openai |
|
|
|
"""# Step 2: Import the two libraries into the code""" |
|
|
|
import gradio as gr |
|
|
|
import openai |
|
|
|
"""Set your OpenAI API Key""" |
|
|
|
openai.api_key = "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" |
|
|
|
"""# Step 3: Now define the fuction that will bring gpt.3.5.turbo (also called text-davinci-003) into your code""" |
|
|
|
def chatbot(input): |
|
|
|
|
|
prompt = "You only answer questions about chronic kidney disease (CKD). If the question is not about chronic kidney disease, you politely respond that you are not designed to answer that kind of question.\n\n" + input |
|
|
|
response = openai.Completion.create( |
|
engine="text-davinci-003", |
|
prompt=prompt, |
|
temperature=0.5, |
|
max_tokens=100 |
|
) |
|
return response.choices[0].text.strip() |
|
|
|
"""# Step 4: Setup the gradio chatbot interface""" |
|
|
|
iface = gr.Interface( |
|
fn=chatbot, |
|
inputs="text", |
|
outputs="text", |
|
title="CKD-AI 2.0", |
|
layout="vertical", |
|
inputs_css_class="custom-input-class", |
|
outputs_css_class="custom-output-class", |
|
examples=None, |
|
output_width="100%", |
|
output_height=400, |
|
css=""" |
|
.custom-input-class { |
|
/* Custom input component styles */ |
|
} |
|
.custom-output-class { |
|
/* Custom output component styles */ |
|
} |
|
.gradio-interface input[type="submit"] { |
|
background: linear-gradient(45deg, #FF0000, #FF4500); /* Red gradient background */ |
|
color: #FFFFFF; /* White text color */ |
|
} |
|
/* Other custom CSS rules */ |
|
""" |
|
) |
|
|
|
"""# Step 5: Launch the chatbot |
|
|
|
Finally, launch the chatbot |
|
""" |
|
|
|
iface.launch(share=True) |