DelaliScratchwerk commited on
Commit
a3ce5e8
·
verified ·
1 Parent(s): 1524eca

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ MODEL_ID = "your-username/text-period-setfit"
5
+ pipe = pipeline("text-classification", model=MODEL_ID, return_all_scores=True)
6
+
7
+ def predict(txt):
8
+ scores = pipe(txt)[0]
9
+ scores = sorted(scores, key=lambda d: d["score"], reverse=True)
10
+ top = scores[0]["label"]
11
+ table = {s["label"]: round(float(s["score"]), 4) for s in scores}
12
+ return top, table
13
+
14
+ demo = gr.Interface(
15
+ fn=predict,
16
+ inputs=gr.Textbox(lines=8, label="Paste text"),
17
+ outputs=[gr.Label(label="Predicted Period"), gr.JSON(label="Scores")],
18
+ title="Text → Time Period"
19
+ )
20
+
21
+ if __name__ == "__main__":
22
+ demo.launch()