alperugurcan commited on
Commit
6471c66
·
verified ·
1 Parent(s): d90a142

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+ import torch
4
+
5
+ model_name = "alperugurcan/nlp-disaster"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
+
9
+ def predict(text):
10
+ # Tokenize the input text
11
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
12
+ # Get model predictions
13
+ with torch.no_grad():
14
+ outputs = model(**inputs)
15
+ predictions = torch.argmax(outputs.logits, dim=-1)
16
+ return "Positive" if predictions.item() == 1 else "Negative"
17
+
18
+ # Create a Gradio interface
19
+ iface = gr.Interface(fn=predict,
20
+ inputs="text",
21
+ outputs="text",
22
+ title="Sentiment Analysis",
23
+ description="Enter text to analyze sentiment (Positive/Negative).")
24
+
25
+ # Launch the app
26
+ iface.launch()