willco-afk commited on
Commit
9778ff0
·
verified ·
1 Parent(s): 9a35fb1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+ import torch
4
+
5
+ # Replace this with your actual model name
6
+ model_name = "willco-afk/my-model-name"
7
+
8
+ # Load the model and tokenizer from Hugging Face Hub
9
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
10
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
11
+
12
+ # Function to predict language from input text
13
+ def predict_language(text):
14
+ # Tokenize the input text
15
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
16
+
17
+ # Get predictions from the model
18
+ with torch.no_grad():
19
+ outputs = model(**inputs)
20
+
21
+ # Get the logits (raw predictions) and apply softmax to get probabilities
22
+ logits = outputs.logits
23
+ predicted_class = logits.argmax(dim=-1).item()
24
+
25
+ # Return the predicted class label (you can map this to your language labels)
26
+ label_map = {0: "english", 1: "spanish", 2: "tagalog"}
27
+ return label_map.get(predicted_class, "Unknown")
28
+
29
+ # Create a Gradio interface for the model
30
+ iface = gr.Interface(fn=predict_language, inputs="text", outputs="text", title="Slang Language Classifier")
31
+
32
+ # Launch the interface
33
+ iface.launch()