hiba9 commited on
Commit
5114235
1 Parent(s): a08fefc

Rename project_2b.py to app.py

Browse files
Files changed (1) hide show
  1. project_2b.py → app.py +72 -58
project_2b.py → app.py RENAMED
@@ -1,11 +1,21 @@
1
- # -*- coding: utf-8 -*-
2
- """Project 2B.ipynb
 
 
 
 
 
 
 
 
 
3
 
4
- Automatically generated by Colab.
 
 
5
 
6
- Original file is located at
7
- https://colab.research.google.com/drive/1DZjrQCfQQ3LfSVDKMae3N7I_wKQU3c9a
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
- df = pd.read_csv("sample_data/Restaurant_Reviews.tsv", sep='\t')
25
- df=df.head(200)
26
- df.shape
27
-
28
- df.head()
29
-
30
- sns.countplot(x='Liked', data=df)
31
- plt.title('Sentiment Distribution (0 = Negative, 1 = Positive)')
32
- plt.show()
33
-
34
- example=df['Review'][56]
35
- example
36
-
37
- vectorizer = TfidfVectorizer(max_features=5000)
38
- X = vectorizer.fit_transform(df['Review'])
39
- y = df['Liked']
40
-
41
-
42
-
43
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
44
-
45
-
46
-
47
- model = LogisticRegression()
48
- model.fit(X_train, y_train)
49
-
50
-
51
-
52
- y_pred = model.predict(X_test)
53
- print(classification_report(y_test, y_pred))
54
-
55
- cm = confusion_matrix(y_test, y_pred)
56
- sns.heatmap(cm, annot=True, fmt='d', cmap='Blues', xticklabels=model.classes_, yticklabels=model.classes_)
57
- plt.xlabel('Predicted')
58
- plt.ylabel('Actual')
59
- plt.title('Confusion Matrix')
60
- plt.show()
61
-
62
-
63
-
64
- import ipywidgets as widgets
65
- from IPython.display import display
66
-
67
- def predict_sentiment(review):
68
- # Transform the input review using the vectorizer
69
- input_vector = vectorizer.transform([review])
70
-
71
- # Predict sentiment
72
- prediction = model.predict(input_vector)[0]
73
-
74
- # Return the sentiment prediction
75
- return "Positive" if prediction == 1 else "Negative"
 
 
 
 
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(