robertselvam's picture
Update app.py
845d7b1
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()