naughtondale
commited on
Commit
•
488206f
1
Parent(s):
10fe9ad
Upload ckd_gradio1.py
Browse files- ckd_gradio1.py +74 -0
ckd_gradio1.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""CKD-Gradio1.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1Iy_x9Rvc62uZ-G5gQNejVwypnWFtMPkz
|
8 |
+
|
9 |
+
# Step 1: Install the required libraries for the chatbot to function
|
10 |
+
"""
|
11 |
+
|
12 |
+
!pip install gradio
|
13 |
+
|
14 |
+
!pip install openai
|
15 |
+
|
16 |
+
"""# Step 2: Import the two libraries into the code"""
|
17 |
+
|
18 |
+
import gradio as gr
|
19 |
+
|
20 |
+
import openai
|
21 |
+
|
22 |
+
"""Set your OpenAI API Key"""
|
23 |
+
|
24 |
+
openai.api_key = "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"
|
25 |
+
|
26 |
+
"""# Step 3: Now define the fuction that will bring gpt.3.5.turbo (also called text-davinci-003) into your code"""
|
27 |
+
|
28 |
+
def chatbot(input):
|
29 |
+
|
30 |
+
# Add system prompt before the user's input
|
31 |
+
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
|
32 |
+
|
33 |
+
response = openai.Completion.create(
|
34 |
+
engine="text-davinci-003", # This is the engine name for GPT-3.5 Turbo
|
35 |
+
prompt=prompt,
|
36 |
+
temperature=0.5,
|
37 |
+
max_tokens=100
|
38 |
+
)
|
39 |
+
return response.choices[0].text.strip()
|
40 |
+
|
41 |
+
"""# Step 4: Setup the gradio chatbot interface"""
|
42 |
+
|
43 |
+
iface = gr.Interface(
|
44 |
+
fn=chatbot,
|
45 |
+
inputs="text",
|
46 |
+
outputs="text",
|
47 |
+
title="CKD-AI 2.0", # Set the interface title
|
48 |
+
layout="vertical", # Set the layout to vertical
|
49 |
+
inputs_css_class="custom-input-class", # Add a custom CSS class to the input component
|
50 |
+
outputs_css_class="custom-output-class", # Add a custom CSS class to the output component
|
51 |
+
examples=None, # Remove examples if not needed
|
52 |
+
output_width="100%", # Make the output box wider
|
53 |
+
output_height=400, # Set the output box height to accommodate more text
|
54 |
+
css="""
|
55 |
+
.custom-input-class {
|
56 |
+
/* Custom input component styles */
|
57 |
+
}
|
58 |
+
.custom-output-class {
|
59 |
+
/* Custom output component styles */
|
60 |
+
}
|
61 |
+
.gradio-interface input[type="submit"] {
|
62 |
+
background: linear-gradient(45deg, #FF0000, #FF4500); /* Red gradient background */
|
63 |
+
color: #FFFFFF; /* White text color */
|
64 |
+
}
|
65 |
+
/* Other custom CSS rules */
|
66 |
+
"""
|
67 |
+
)
|
68 |
+
|
69 |
+
"""# Step 5: Launch the chatbot
|
70 |
+
|
71 |
+
Finally, launch the chatbot
|
72 |
+
"""
|
73 |
+
|
74 |
+
iface.launch(share=True)
|