Ajay12345678980 commited on
Commit
a701122
·
verified ·
1 Parent(s): 57f54a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -1,7 +1,30 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+ import torch
4
 
5
+ # Load model and tokenizer
6
+ model_name = "" # Replace with your model's Hugging Face Hub path
7
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
9
 
10
+ # Define prediction function
11
+ def predict(text):
12
+ inputs = tokenizer(text, return_tensors="pt")
13
+ with torch.no_grad():
14
+ outputs = model(**inputs)
15
+ logits = outputs.logits
16
+ prediction = torch.argmax(logits, dim=1).item()
17
+ return prediction
18
+
19
+ # Set up Gradio interface
20
+ interface = gr.Interface(
21
+ fn=predict,
22
+ inputs="text",
23
+ outputs="text",
24
+ title="My Model Prediction",
25
+ description="Enter some text and see what the model predicts!"
26
+ )
27
+
28
+ # Launch the Gradio app
29
+ if __name__ == "__main__":
30
+ interface.launch()