test_space / app.py
upinat's picture
Update app.py
44c722e
raw
history blame contribute delete
No virus
1.3 kB
import gradio as gr
def greet(name):
return "Hello " + name + "!!"
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()
'''
import gradio as gr
import torch
import torch.nn as nn
import torchtext
import spacy
import string
# 下载和加载情感分类模型
model = torch.hub.load('pytorch/vision', 'resnet18', pretrained=True)
model.eval()
# 创建一个文本处理pipeline
nlp = spacy.load("en_core_web_sm")
tokenizer = torchtext.data.utils.get_tokenizer("spacy", language="en_core_web_sm")
def preprocess_text(text):
text = text.lower()
text = ''.join([char for char in text if char not in string.punctuation])
text = ' '.join([token.text for token in nlp(text)])
text = tokenizer(text)
return ' '.join(text)
# 定义文本情感分类函数
def classify_text(text):
text = preprocess_text(text)
# 在这里实际上应该用您自己的情感分类模型进行预测
# 此示例仅用ResNet-18模型进行占位
return {"emotion": "Placeholder"}
# 创建Gradio界面
iface = gr.Interface(
fn=classify_text,
inputs="text",
outputs="label",
interpretation="default",
title="Text Emotion Classification",
description="Enter a text and get its emotion classification."
)
# 启动界面
iface.launch()
'''