ireneminhee's picture
Upload 3 files
d6c9be2 verified
raw
history blame
1.52 kB
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyOewSj8PHA49VeNmaZxMZGo"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"SPAkgiSviyO0"},"outputs":[],"source":["import gradio as gr\n","import torch\n","from transformers import AutoModelForSequenceClassification, AutoTokenizer\n","\n","# ๋ชจ๋ธ ๊ฒฝ๋กœ ์„ค์ •\n","model_path = \"./model\" # ์—…๋กœ๋“œ๋œ ๋ชจ๋ธ ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ\n","\n","# ๋ชจ๋ธ๊ณผ ํ† ํฌ๋‚˜์ด์ € ๋กœ๋“œ\n","model = AutoModelForSequenceClassification.from_pretrained(model_path)\n","tokenizer = AutoTokenizer.from_pretrained(\"klue/bert-base\")\n","\n","# ์˜ˆ์ธก ํ•จ์ˆ˜\n","def predict(text):\n"," inputs = tokenizer(text, return_tensors=\"pt\")\n"," outputs = model(**inputs)\n"," probabilities = torch.sigmoid(outputs.logits)\n"," depression_prob = probabilities[0, 1].item()\n","\n"," if depression_prob > 0.5:\n"," return f\"Depressed (Confidence: {depression_prob:.2%})\"\n"," else:\n"," return f\"Not Depressed (Confidence: {1 - depression_prob:.2%})\"\n","\n","# Gradio ์ธํ„ฐํŽ˜์ด์Šค\n","interface = gr.Interface(\n"," fn=predict,\n"," inputs=gr.Textbox(label=\"Enter your text here\"),\n"," outputs=gr.Textbox(label=\"Result\"),\n"," title=\"Depression Detection\",\n"," description=\"Predict the likelihood of depression based on text input.\",\n",")\n","\n","interface.launch()\n"]}]}