# -*- coding: utf-8 -*- """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): # Add system prompt before the user's 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", # This is the engine name for GPT-3.5 Turbo 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", # Set the interface title layout="vertical", # Set the layout to vertical inputs_css_class="custom-input-class", # Add a custom CSS class to the input component outputs_css_class="custom-output-class", # Add a custom CSS class to the output component examples=None, # Remove examples if not needed output_width="100%", # Make the output box wider output_height=400, # Set the output box height to accommodate more text 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)