File size: 2,204 Bytes
488206f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# -*- 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)