Spaces:
Sleeping
Sleeping
{"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"]}]} |