MaryahGreene commited on
Commit
f1f3480
·
verified ·
1 Parent(s): 4893ff7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -2,15 +2,23 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
  import gradio as gr
3
  import torch
4
 
5
- model = AutoModelForSequenceClassification.from_pretrained("my-archflava-model")
6
- tokenizer = AutoTokenizer.from_pretrained("my-archflava-model")
7
 
8
- def classify_text(text):
 
 
 
 
 
 
 
 
9
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
10
  with torch.no_grad():
11
  outputs = model(**inputs)
12
- prediction = torch.argmax(outputs.logits, dim=1).item()
13
- return str(prediction)
14
 
15
- iface = gr.Interface(fn=classify_text, inputs="text", outputs="text")
16
- iface.launch()
 
2
  import gradio as gr
3
  import torch
4
 
5
+ model = AutoModelForSequenceClassification.from_pretrained("my-flava-model")
6
+ tokenizer = AutoTokenizer.from_pretrained("my-flava-model")
7
 
8
+ # Map label numbers to string categories (customize this part!)
9
+ label_map = {
10
+ 0: "Spicy",
11
+ 1: "Mild",
12
+ 2: "Tangy",
13
+ 3: "Salty"
14
+ }
15
+
16
+ def classify(text):
17
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
18
  with torch.no_grad():
19
  outputs = model(**inputs)
20
+ pred = torch.argmax(outputs.logits, dim=1).item()
21
+ return label_map[pred]
22
 
23
+ demo = gr.Interface(fn=classify, inputs="text", outputs="text", title="What's Your Flava?")
24
+ demo.launch()