ireneminhee's picture
Update app.py
7c3c2e7 verified
# -*- 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()