Karthikeyan commited on
Commit
f5ad618
·
1 Parent(s): b3f3db2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import os
4
+ # Initialize the OpenAI API client with your actual API key
5
+
6
+ class Classifier:
7
+ def __init__(self):
8
+ openai.api_key = os.getenv("OPENAI_API_KEY")
9
+ def classify_text(self,text):
10
+ # Specify the desired model and additional options
11
+ response = openai.Completion.create(
12
+ engine="text-davinci-003",
13
+ prompt=f"Classify the following text as 'True' if related to Mental healthcare issue or 'False' if not related:\n{text}\n",
14
+ temperature=0,
15
+ max_tokens=1, # We only need a single token as the classification result
16
+ n=1,
17
+ stop=None,
18
+ )
19
+
20
+ # Extract and return the generated classification result
21
+ generated_text = response.choices[0].text.strip()
22
+ return generated_text
23
+ def clear_func(self):
24
+ return " "," "
25
+ def gradio_interface(self):
26
+ with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as demo:
27
+ gr.HTML("""<center><h1>Mental healthcare</h1></center>""")
28
+ with gr.Column(elem_id="col-container"):
29
+ with gr.Row(elem_id="row-flex"):
30
+ with gr.Column(scale=0.90, min_width=160):
31
+ question =gr.Textbox(
32
+ show_label=True,
33
+ label="Question",
34
+ ).style(container=True)
35
+ with gr.Column(scale=0.10, min_width=160):
36
+ result =gr.Textbox(
37
+ show_label=True,
38
+ label="Result",
39
+ ).style(container=True)
40
+ with gr.Row(elem_id="row-flex"):
41
+ with gr.Column(scale=0.50, min_width=0):
42
+ submit=gr.Button(value="Submit")
43
+ with gr.Column(scale=0.50):
44
+ emptyBtn = gr.Button("🧹 Clear",)
45
+
46
+ submit.click(self.classify_text,question,result)
47
+ emptyBtn.click(self.clear_func,[],[question,result])
48
+
49
+ demo.queue().launch(debug=True)
50
+
51
+ if __name__ == "__main__":
52
+ classifier = Classifier()
53
+ classifier.gradio_interface()