File size: 1,232 Bytes
725b5b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()