Spaces:
Sleeping
Sleeping
Rename project_2b.py to app.py
Browse files- project_2b.py → app.py +72 -58
project_2b.py → app.py
RENAMED
@@ -1,11 +1,21 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
"""
|
9 |
|
10 |
import pandas as pd
|
11 |
from sklearn.model_selection import train_test_split
|
@@ -21,58 +31,62 @@ from wordcloud import WordCloud
|
|
21 |
import zipfile
|
22 |
import os
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
df.
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
76 |
|
77 |
# Text input widget
|
78 |
review_input = widgets.Text(
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import os
|
4 |
+
os.system('pip install transformers')
|
5 |
+
import os
|
6 |
+
os.system('pip install torch')
|
7 |
+
import os
|
8 |
+
os.system('pip install tensorflow')
|
9 |
+
import os
|
10 |
+
os.system('pip install soundfile')
|
11 |
+
import soundfile as sf
|
12 |
|
13 |
+
from transformers import VitsModel, AutoTokenizer
|
14 |
+
import numpy as np
|
15 |
+
import io
|
16 |
|
17 |
+
import torch
|
18 |
+
print(torch.__version__)
|
|
|
19 |
|
20 |
import pandas as pd
|
21 |
from sklearn.model_selection import train_test_split
|
|
|
31 |
import zipfile
|
32 |
import os
|
33 |
|
34 |
+
model = VitsModel.from_pretrained("facebook/mms-tts-eng")
|
35 |
+
tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-eng")
|
36 |
+
|
37 |
+
def generate_speech(text):
|
38 |
+
df = pd.read_csv("sample_data/Restaurant_Reviews.tsv", sep='\t')
|
39 |
+
df=df.head(200)
|
40 |
+
df.shape
|
41 |
+
|
42 |
+
df.head()
|
43 |
+
|
44 |
+
sns.countplot(x='Liked', data=df)
|
45 |
+
plt.title('Sentiment Distribution (0 = Negative, 1 = Positive)')
|
46 |
+
plt.show()
|
47 |
+
|
48 |
+
example=df['Review'][56]
|
49 |
+
example
|
50 |
+
|
51 |
+
vectorizer = TfidfVectorizer(max_features=5000)
|
52 |
+
X = vectorizer.fit_transform(df['Review'])
|
53 |
+
y = df['Liked']
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
model = LogisticRegression()
|
62 |
+
model.fit(X_train, y_train)
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
y_pred = model.predict(X_test)
|
67 |
+
print(classification_report(y_test, y_pred))
|
68 |
+
|
69 |
+
cm = confusion_matrix(y_test, y_pred)
|
70 |
+
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues', xticklabels=model.classes_, yticklabels=model.classes_)
|
71 |
+
plt.xlabel('Predicted')
|
72 |
+
plt.ylabel('Actual')
|
73 |
+
plt.title('Confusion Matrix')
|
74 |
+
plt.show()
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
import ipywidgets as widgets
|
79 |
+
from IPython.display import display
|
80 |
+
|
81 |
+
def predict_sentiment(review):
|
82 |
+
# Transform the input review using the vectorizer
|
83 |
+
input_vector = vectorizer.transform([review])
|
84 |
+
|
85 |
+
# Predict sentiment
|
86 |
+
prediction = model.predict(input_vector)[0]
|
87 |
+
|
88 |
+
# Return the sentiment prediction
|
89 |
+
return "Positive" if prediction == 1 else "Negative"
|
90 |
|
91 |
# Text input widget
|
92 |
review_input = widgets.Text(
|