Spaces:
Build error
Build error
| # -*- coding: utf-8 -*- | |
| """app.py | |
| Automatically generated by Colab. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1eyNEXhQE4T_7cq-MsPQ77p7h6xdrOpzk | |
| """ | |
| import gradio as gr | |
| import torch | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| # ๋ชจ๋ธ ๊ฒฝ๋ก ์ค์ | |
| model_path = "./model" # ์ ๋ก๋๋ ๋ชจ๋ธ ๋๋ ํ ๋ฆฌ ๊ฒฝ๋ก | |
| # ๋ชจ๋ธ๊ณผ ํ ํฌ๋์ด์ ๋ก๋ | |
| model = AutoModelForSequenceClassification.from_pretrained(model_path) | |
| tokenizer = AutoTokenizer.from_pretrained("klue/bert-base") | |
| # ์์ธก ํจ์ | |
| def predict(text): | |
| inputs = tokenizer(text, return_tensors="pt") | |
| outputs = model(**inputs) | |
| probabilities = torch.sigmoid(outputs.logits) | |
| depression_prob = probabilities[0, 1].item() | |
| if depression_prob > 0.5: | |
| return f"Depressed (Confidence: {depression_prob:.2%})" | |
| else: | |
| return f"Not Depressed (Confidence: {1 - depression_prob:.2%})" | |
| # Gradio ์ธํฐํ์ด์ค | |
| interface = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Textbox(label="Enter your text here"), | |
| outputs=gr.Textbox(label="Result"), | |
| title="Depression Detection", | |
| description="Predict the likelihood of depression based on text input.", | |
| ) | |
| interface.launch() |