Spaces:
Build error
Build error
Commit
·
32f54f5
1
Parent(s):
b1270c4
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,16 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
# Read requirements.txt file
|
| 6 |
-
with open('requirements.txt', 'r') as req_file:
|
| 7 |
-
requirements = req_file.read().splitlines
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
| 13 |
-
# Load and preprocess the IMDB dataset from CSV
|
| 14 |
-
preprocessed_data = []
|
| 15 |
-
with open('IMDB Dataset.csv', 'r') as csv_file:
|
| 16 |
-
csv_reader = csv.DictReader(csv_file)
|
| 17 |
-
for row in csv_reader:
|
| 18 |
-
text = row['review']
|
| 19 |
-
label = row['sentiment']
|
| 20 |
-
preprocessed_entry = {
|
| 21 |
-
'text': text,
|
| 22 |
-
'label': label
|
| 23 |
-
}
|
| 24 |
-
preprocessed_data.append(preprocessed_entry)
|
| 25 |
|
| 26 |
-
# Convert the preprocessed data to a pandas DataFrame
|
| 27 |
-
df = pandas.DataFrame(preprocessed_data)
|
| 28 |
|
| 29 |
-
# Convert the DataFrame to a datasets dataset
|
| 30 |
-
dataset = Dataset.from_pandas(df)
|
| 31 |
-
|
| 32 |
-
# Tokenize the dataset
|
| 33 |
-
tokenizer = AutoTokenizer.from_pretrained("bigscience/bloom-560m")
|
| 34 |
-
def tokenize_function(examples):
|
| 35 |
-
return tokenizer(examples["text"], padding="max_length", truncation=True)
|
| 36 |
-
|
| 37 |
-
tokenized_datasets = dataset.map(tokenize_function, batched=True)
|
| 38 |
-
|
| 39 |
-
# Fine-tune the Bloom model
|
| 40 |
-
model = AutoModelForSequenceClassification.from_pretrained("bigscience/bloom-560m", num_labels=2)
|
| 41 |
-
|
| 42 |
-
training_args = TrainingArguments(output_dir="test_trainer")
|
| 43 |
-
|
| 44 |
-
import numpy as np
|
| 45 |
-
import evaluate
|
| 46 |
-
|
| 47 |
-
metric = evaluate.load("accuracy")
|
| 48 |
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
pipe = pipeline ('sentiment-analysis')
|
| 5 |
+
text = st.text_area('enter some text!')
|
| 6 |
+
def predict_sentiment(text):
|
| 7 |
+
result = pipe(text)[0]
|
| 8 |
+
return result['label']
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
iface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text")
|
| 12 |
+
iface.launch()
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
|
|
|
|
|
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|