Spaces:
Runtime error
Runtime error
File size: 1,631 Bytes
1bac8d3 |
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import gradio as gr
import markdownify
import html as pyhtml
from setfit import SetFitModel
model = SetFitModel.from_pretrained("./predictor_2")
def clean_text(text):
text = markdownify.markdownify(
pyhtml.unescape(text or ""),
heading_style="ATX").strip()
if len(text) > 250:
text = text[:250] + "..."
return text
def text_template(title="",description="",url="",comment=""):
description = clean_text(description)
comment = clean_text(comment)
return f"""Title: "{title}"
Description: "{description}"
Url: "{url}"
First Comment: "{
comment
}\""""
def text_classifier(title="",description="",url="",comment=""):
text = text_template(title,description,url,comment)
prediction = model.predict_proba([text])[0]
a,b = prediction
return {'non-ai': float(a), 'ai': float(b)}
inputs = [
gr.Textbox(
value="",
label="Title"
),
gr.Textbox(
value="",
label="Description"
),
gr.Textbox(
value="",
label="URL"
),
gr.Textbox(
value="",
label="Comment"
),
]
demo = gr.Interface(fn=text_classifier,
inputs=inputs,
outputs="label")
demo.launch(show_api=True)
|