updates
Browse files
app.old
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def image_classifier(inp):
|
| 4 |
+
return {'cat': 0.3, 'dog': 0.7}
|
| 5 |
+
|
| 6 |
+
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
|
| 7 |
+
demo.launch()
|
app.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
def predict_emotion(text):
|
| 4 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
|
| 5 |
+
outputs = model(**inputs)
|
| 6 |
+
prediction = outputs.logits.argmax(-1).item()
|
| 7 |
+
return dataset["train"].features["label"].int2str(prediction)
|
| 8 |
|
| 9 |
+
interface = gr.Interface(fn=predict_emotion, inputs="text", outputs="label", title="Emotion Classifier")
|
| 10 |
+
interface.launch(share=False)
|
train.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datasets import load_dataset
|
| 2 |
+
from transformers import AutoTokenizer
|
| 3 |
+
from transformers import AutoModelForSequenceClassification, TrainingArguments, Trainer
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
dataset = load_dataset("emotion")
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
| 8 |
+
|
| 9 |
+
def tokenize_function(examples):
|
| 10 |
+
return tokenizer(examples["text"], padding="max_length", truncation=True, max_length=128)
|
| 11 |
+
|
| 12 |
+
tokenized_datasets = dataset.map(tokenize_function, batched=True)
|
| 13 |
+
|
| 14 |
+
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased", num_labels=6)
|
| 15 |
+
|
| 16 |
+
training_args = TrainingArguments(
|
| 17 |
+
output_dir="./results",
|
| 18 |
+
num_train_epochs=1, # Reduce epochs for faster training
|
| 19 |
+
per_device_train_batch_size=8, # Smaller batch size to fit CPU
|
| 20 |
+
logging_dir="./logs",
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
trainer = Trainer(
|
| 24 |
+
model=model,
|
| 25 |
+
args=training_args,
|
| 26 |
+
train_dataset=tokenized_datasets["train"],
|
| 27 |
+
eval_dataset=tokenized_datasets["validation"]
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
trainer.train()
|