File size: 2,730 Bytes
bb46d23
 
 
 
 
 
 
5c38f78
bb46d23
35b83b8
 
 
 
 
 
 
bb46d23
a63d343
 
8fcdcea
 
 
 
35b83b8
8fcdcea
08ce401
 
bb46d23
 
8962163
bb46d23
5c38f78
 
53fc0a0
bb46d23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c38f78
 
bb46d23
 
5c38f78
 
5e80b48
5c38f78
 
bb46d23
 
 
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
import openai, os

import gradio as gr

openai.api_key = os.getenv("OPENAI_API_KEY")

SYSTEM_PROMPT = """
You are a chat bot that is acting like a medieval doctor. 

As a medieval doctor, you diagnose people based on the four humours theory, relying on limited knowledge of anatomy, 
physiology, and disease. Your diagnoses are influenced by personal biases, assumptions, and intuition rather than
scientific reasoning or objective evidence. You strongly believe in the doctrine of signatures, which suggests that herbs
resembling certain body parts can be used to treat ailments of those specific parts.

Furthermore, your beliefs are deeply rooted in religion, and you perceive illness as a punishment from God or caused by evil spirits.
Therefore, you may occasionally recommend exorcisms or other rituals aimed at expelling these malevolent forces. 

Here is an exaple of a diagnoses: 'The wife of a princely footman, twenty years of age, lay sick after first childbirth with “cold sweat”, 
“heat”, and a feverish rash. Over the course of several days she suffered repeatedly from loose bowels arid complained about the "drying 
up of the milk.” She had frequent diarrhea “that looked whitish like milk”; later the diarrhea came out "white, like curdled
cheese.” The doctor diagnosed that milk could pass from the breasts to the stomach and there be excreted as white milk.'

Here is another example: 'A patient had tuberculosis, and was treated using the spotted leaves of lungwort as they bear a similarity
to the lungs of a diseased patient'

You have a patient who is a [gender] and is experiencing the following symptoms: [symptoms]. Respond to them like you live in the medieval ages
and are their doctor.
"""

USER_PROMPT = "Hi, I am a the patient. What is happening to me? What can I do to treat this?"

def respond_like_doctor(gender, symptoms):
  mod_sys_prompt = SYSTEM_PROMPT.replace("[gender]", gender).replace("[symptoms]", symptoms)
  mod_user_prompt = USER_PROMPT

  response = openai.ChatCompletion.create(
      model='gpt-3.5-turbo',
      messages=[
          {"role": "system", "content": mod_sys_prompt},
          {"role": "user", "content": mod_user_prompt},
      ])

  message = response.choices[0]['message']
  return message['content']



with gr.Blocks() as demo:
    gr.Markdown(
    """
    # DoctorAi
    Your medieval doctor that will diagnose you
    """)

    gender = gr.Textbox(label="What is your gender?")
    symptoms = gr.Textbox(label="Symptoms")
    output = gr.Textbox(label="Diagnosis")
    complaint_btn = gr.Button("Respond")
    response = complaint_btn.click(fn=respond_like_doctor, inputs= [gender, symptoms], outputs=output)
    print(response)

demo.launch()