File size: 1,231 Bytes
c37d9d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c3c2e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- 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()