File size: 2,187 Bytes
f5ad618
 
 
 
 
 
 
 
 
 
 
 
845d7b1
21d273b
a06fbf0
f5ad618
e458603
f5ad618
 
 
 
 
 
 
a06fbf0
f5ad618
 
a06fbf0
f5ad618
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import openai
import os
# Initialize the OpenAI API client with your actual API key

class Classifier:
    def __init__(self):
      openai.api_key = os.getenv("OPENAI_API_KEY")
    def classify_text(self,text):
      # Specify the desired model and additional options
      response = openai.Completion.create(
          engine="text-davinci-003",
          prompt = f"""Your are Mental healthcare Assistant. Classify the following input message from the patient if the message related to Mental healtcare issue return 'True', Else not related return 'False':
                    ```message from the patient: {text}```
                    """ ,
          temperature=0,
          max_tokens=50,  # We only need a single token as the classification result
          n=1,
          stop=None,
      )

      # Extract and return the generated classification result
      generated_text = response.choices[0].text.strip()
      return generated_text
        
    def clear_func(self):
      return " "," "
        
    def gradio_interface(self):
      with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as demo:
        gr.HTML("""<center><h1>Mental healthcare</h1></center>""")
        with gr.Column(elem_id="col-container"):
          with gr.Row(elem_id="row-flex"):
            with gr.Column(scale=0.90, min_width=160):
              question =gr.Textbox(
                  show_label=True,
                  label="Question",
              ).style(container=True)
            with gr.Column(scale=0.10, min_width=160):
              result =gr.Textbox(
                  show_label=True,
                  label="Result",
              ).style(container=True)
          with gr.Row(elem_id="row-flex"):
            with gr.Column(scale=0.50, min_width=0):
                submit=gr.Button(value="Submit")
            with gr.Column(scale=0.50):
                emptyBtn = gr.Button("🧹 Clear",)
          
        submit.click(self.classify_text,question,result)
        emptyBtn.click(self.clear_func,[],[question,result])

      demo.queue().launch(debug=True)

if __name__ == "__main__":
    classifier = Classifier()
    classifier.gradio_interface()