wongshennan commited on
Commit
fab1b4a
β€’
1 Parent(s): 8474fdd

add app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
3
+
4
+ # Authenticate with Hugging Face (if needed)
5
+ # from transformers import set_token
6
+ # set_token("your_hugging_face_token_here")
7
+
8
+ # Load your self-hosted model
9
+ model_name = "22A223R/bert-ITI110" # Replace with your model's path
10
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
11
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
12
+
13
+ # Initialize the pipeline with your model
14
+ classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
15
+
16
+ def classify_text(text):
17
+ result = classifier(text)[0]
18
+ label = result['label']
19
+ score = round(result['score'], 4)
20
+ return f"Label: {label}, Score: {score}"
21
+
22
+ iface = gr.Interface(fn=classify_text,
23
+ inputs=gr.inputs.Textbox(lines=2, placeholder="Type your text here..."),
24
+ outputs="text",
25
+ title="Text Classification with Self-Hosted Hugging Face Model",
26
+ description="This model classifies the input text. Try it out!")
27
+
28
+ iface.launch()