Spaces:
Sleeping
Sleeping
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() |