maxsi commited on
Commit
bbffd8d
·
1 Parent(s): b7b8b1d

With CVS File

Browse files
Files changed (4) hide show
  1. .gitignore +164 -0
  2. app.py +105 -0
  3. mockup_feedback_posts.csv +11 -0
  4. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Python template
2
+ # Byte-compiled / optimized / DLL files
3
+ __pycache__/
4
+ *.py[cod]
5
+ *$py.class
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ #Pipfile.lock
97
+
98
+ # poetry
99
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103
+ #poetry.lock
104
+
105
+ # pdm
106
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107
+ #pdm.lock
108
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109
+ # in version control.
110
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
111
+ .pdm.toml
112
+ .pdm-python
113
+ .pdm-build/
114
+
115
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116
+ __pypackages__/
117
+
118
+ # Celery stuff
119
+ celerybeat-schedule
120
+ celerybeat.pid
121
+
122
+ # SageMath parsed files
123
+ *.sage.py
124
+
125
+ # Environments
126
+ .env
127
+ .venv
128
+ env/
129
+ venv/
130
+ ENV/
131
+ env.bak/
132
+ venv.bak/
133
+
134
+ # Spyder project settings
135
+ .spyderproject
136
+ .spyproject
137
+
138
+ # Rope project settings
139
+ .ropeproject
140
+
141
+ # mkdocs documentation
142
+ /site
143
+
144
+ # mypy
145
+ .mypy_cache/
146
+ .dmypy.json
147
+ dmypy.json
148
+
149
+ # Pyre type checker
150
+ .pyre/
151
+
152
+ # pytype static type analyzer
153
+ .pytype/
154
+
155
+ # Cython debug symbols
156
+ cython_debug/
157
+
158
+ # PyCharm
159
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
162
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
163
+ #.idea/
164
+
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import pandas as pd
4
+ import io
5
+ import csv
6
+ import os
7
+
8
+ # Initialize the zero-shot classification pipeline
9
+ classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
10
+
11
+ # Define the candidate labels for sentiment analysis
12
+ candidate_labels = ["positive", "negative", "neutral"]
13
+
14
+ def analyze_sentiment(text):
15
+ """
16
+ Analyze sentiment of a single post using zero-shot classification
17
+ """
18
+ result = classifier(text, candidate_labels)
19
+ # Get the label with highest score
20
+ sentiment = result['labels'][0]
21
+ return sentiment
22
+
23
+ def process_csv(file):
24
+ """
25
+ Process posts from CSV file and return results as a CSV file
26
+ """
27
+ try:
28
+ # Read the input CSV file
29
+ df = pd.read_csv(file.name)
30
+
31
+ # Verify required columns exist
32
+ if 'post_id' not in df.columns or 'text' not in df.columns:
33
+ return None, "Error: CSV must contain 'post_id' and 'text' columns"
34
+
35
+ # Apply sentiment analysis to each row
36
+ df['sentiment'] = df['text'].apply(analyze_sentiment)
37
+
38
+ # Create output CSV file
39
+ output_file = "sentiment_analysis_results.csv"
40
+ df.to_csv(output_file, index=False)
41
+
42
+ return output_file, "Analysis completed successfully!"
43
+
44
+ except Exception as e:
45
+ return None, f"Error processing CSV: {str(e)}"
46
+
47
+ # Create example CSV file
48
+ def create_example_file():
49
+ """
50
+ Create an example CSV file for demonstration
51
+ """
52
+ example_data = {
53
+ 'post_id': [1, 2, 3],
54
+ 'text': [
55
+ "I absolutely love this product! Best purchase ever!",
56
+ "This is terrible service, never coming back.",
57
+ "The weather is quite nice today."
58
+ ]
59
+ }
60
+ df = pd.DataFrame(example_data)
61
+ example_file = "example_input.csv"
62
+ df.to_csv(example_file, index=False)
63
+ return example_file
64
+
65
+ # Create the example file before launching the interface
66
+ example_file = create_example_file()
67
+
68
+ # Create Gradio interface
69
+ iface = gr.Interface(
70
+ fn=process_csv,
71
+ inputs=[
72
+ gr.File(
73
+ label="Upload CSV file",
74
+ file_types=[".csv"]
75
+ )
76
+ ],
77
+ outputs=[
78
+ gr.File(label="Download Results"),
79
+ gr.Textbox(label="Status")
80
+ ],
81
+ title="Social Media Sentiment Analyzer",
82
+ description="""
83
+ Analyze the sentiment of multiple social media posts using zero-shot classification.
84
+
85
+ Input CSV format:
86
+ - Required columns: 'post_id', 'text'
87
+ - Each row should contain a unique post ID and the post text
88
+
89
+ Output CSV will contain:
90
+ - post_id: Original post ID
91
+ - text: Original post text
92
+ - sentiment: Analyzed sentiment (positive/negative/neutral)
93
+ """,
94
+ examples=[
95
+ [example_file] # Use the created example file
96
+ ]
97
+ )
98
+
99
+ if __name__ == "__main__":
100
+ # Clean up example file when the program exits
101
+ try:
102
+ iface.launch()
103
+ finally:
104
+ if os.path.exists(example_file):
105
+ os.remove(example_file)
mockup_feedback_posts.csv ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ post_id,text
2
+ 1,"I love the new update to the platform! It's amazing."
3
+ 2,"This app is terrible, it crashes every time I try to use it."
4
+ 3,"The customer service was very helpful, I feel satisfied with the response."
5
+ 4,"I had a great experience shopping here, will definitely come back."
6
+ 5,"The product quality is not what I expected, very disappointed."
7
+ 6,"Absolutely wonderful experience, everything went smoothly."
8
+ 7,I had to wait for a long time before someone attended to me.
9
+ 8,"This is just okay, not the best service I've had."
10
+ 9,Great value for money! I'm really happy with my purchase.
11
+ 10,"I don't think the app is user-friendly, it's too confusing."
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers>=4.46.2
2
+ gradio>=5.5.0
3
+ pandas>=2.2.3