StormyCreeper's picture
Upload 2 files
725b5b0 verified
import gradio as gr
# This is an spaces app that uses the MBTI model to predict the personality type of a user based on the text they input.
import transformers
# use pipline load the model from the hub "models/StormyCreeper/mbtiIE"
modeltypes = ["IE", "SN", "TF", "PJ"]
models = []
for modeltype in modeltypes:
models.append(transformers.pipeline("text-classification", model=f"StormyCreeper/mbti{modeltype}"))
# text = gr.inputs.Textbox(lines=7, label="Enter your text here")
# label0 is i and label1 is e
# return the possibility of the user is introvert and extrovert
def predict_text(text):
prediction = ""
personlity = ""
for i in range(4):
result = models[i](text)[0]["label"]
tmp = int(result[-1])
prediction += modeltypes[i][tmp]
prediction += ": "
prediction += str(models[i](text)[0]["score"])
prediction += "\n"
personlity += modeltypes[i][tmp]
return personlity +"\n" + prediction
# Cannot find empty port in range: 7860-7860. You can specify a different port by setting the GRADIO_SERVER_PORT environment variable or passing the `server_port` parameter to `launch()`.
gr.Interface(fn=predict_text, inputs="text", outputs="text").launch()