willco-afk commited on
Commit
e9af546
·
verified ·
1 Parent(s): 3e50739

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -19
app.py CHANGED
@@ -1,27 +1,19 @@
 
1
  import gradio as gr
2
- from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
- import torch
4
 
5
- # Load the model and tokenizer
6
- model_name = "willco-afk/my-model-name"
7
  tokenizer = AutoTokenizer.from_pretrained(model_name)
8
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
 
10
- def classify_text(text):
11
- # Preprocess text
12
- inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
13
  outputs = model(**inputs)
14
- probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
15
- label = torch.argmax(probs, dim=1).item()
16
- labels = ["english", "spanish", "tagalog"]
17
- return labels[label]
18
-
19
- # Define the Gradio interface
20
- with gr.Blocks() as demo:
21
- gr.Markdown("# Slang Translation Classifier")
22
- input_text = gr.Textbox(label="Enter slang text", lines=1)
23
- output_label = gr.Textbox(label="Predicted Language", interactive=False)
24
- submit_button = gr.Button("Classify")
25
- submit_button.click(classify_text, inputs=[input_text], outputs=[output_label])
26
 
 
 
27
  demo.launch()
 
1
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
  import gradio as gr
 
 
3
 
4
+ # Load the model and tokenizer from your Hugging Face model repository
5
+ model_name = "willco-afk/my-model-name" # Replace with your actual model repo name
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
 
9
+ # Define your prediction function
10
+ def predict(text):
11
+ inputs = tokenizer(text, return_tensors="pt")
12
  outputs = model(**inputs)
13
+ logits = outputs.logits
14
+ prediction = logits.argmax(dim=-1).item()
15
+ return f"Predicted Class: {prediction}"
 
 
 
 
 
 
 
 
 
16
 
17
+ # Gradio UI
18
+ demo = gr.Interface(fn=predict, inputs="text", outputs="text")
19
  demo.launch()