Azie88 commited on
Commit
4f6d6df
·
1 Parent(s): 3435fe7

Initial Commit

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +52 -0
  3. requirements.txt +64 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ venv/
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForSequenceClassification
2
+ from transformers import AutoTokenizer, AutoConfig
3
+ from scipy.special import softmax
4
+ import gradio as gr
5
+
6
+
7
+ model_path = f"Azie88/Coachella_sentiment_analysis_roberta"
8
+
9
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
10
+ config = AutoConfig.from_pretrained(model_path)
11
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
12
+
13
+
14
+ # Preprocess text (username and link placeholders)
15
+ def preprocess(text):
16
+ new_text = []
17
+ for t in text.split(" "):
18
+ t = '@user' if t.startswith('@') and len(t) > 1 else t
19
+ t = 'http' if t.startswith('http') else t
20
+ new_text.append(t)
21
+ return " ".join(new_text)
22
+
23
+
24
+ def sentiment_analysis(text):
25
+ text = preprocess(text)
26
+
27
+ # Tokenization and Class Prediction
28
+ encoded_input = tokenizer(text, return_tensors='pt')
29
+ output = model(**encoded_input)
30
+ scores_ = output[0][0].detach().numpy()
31
+ scores_ = softmax(scores_)
32
+
33
+ # Format output dict of scores
34
+ labels = ['Negative', 'Neutral', 'Positive']
35
+ scores = {l:float(s) for (l,s) in zip(labels, scores_) }
36
+
37
+ return scores
38
+
39
+
40
+ demo = gr.Interface(theme=gr.themes.Base(),
41
+ fn=sentiment_analysis,
42
+ inputs=gr.Textbox(placeholder="Write your tweet here..."),
43
+ outputs="label",
44
+ # interpretation="default",
45
+ examples=[["OMG the Coachella lineup is 🔥"],
46
+ ["This lineup is so trash…"],
47
+ ["Coachella starts tomorrow."]]
48
+ title='Coachella Tweet Sentiment Analysis app',
49
+ description='This app assesses if a tweet related to the #Coachella festival has a positive, neutral or negative sentiment.'
50
+ )
51
+
52
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==24.1.0
2
+ annotated-types==0.7.0
3
+ anyio==4.9.0
4
+ certifi==2025.4.26
5
+ charset-normalizer==3.4.2
6
+ click==8.2.1
7
+ colorama==0.4.6
8
+ fastapi==0.115.12
9
+ ffmpy==0.6.0
10
+ filelock==3.18.0
11
+ fsspec==2025.5.1
12
+ gradio==5.33.0
13
+ gradio_client==1.10.2
14
+ groovy==0.1.2
15
+ h11==0.16.0
16
+ httpcore==1.0.9
17
+ httpx==0.28.1
18
+ huggingface-hub==0.32.4
19
+ idna==3.10
20
+ Jinja2==3.1.6
21
+ markdown-it-py==3.0.0
22
+ MarkupSafe==3.0.2
23
+ mdurl==0.1.2
24
+ mpmath==1.3.0
25
+ networkx==3.4.2
26
+ numpy==2.2.6
27
+ orjson==3.10.18
28
+ packaging==25.0
29
+ pandas==2.3.0
30
+ pillow==11.2.1
31
+ pydantic==2.11.5
32
+ pydantic_core==2.33.2
33
+ pydub==0.25.1
34
+ Pygments==2.19.1
35
+ python-dateutil==2.9.0.post0
36
+ python-multipart==0.0.20
37
+ pytz==2025.2
38
+ PyYAML==6.0.2
39
+ regex==2024.11.6
40
+ requests==2.32.3
41
+ rich==14.0.0
42
+ ruff==0.11.13
43
+ safehttpx==0.1.6
44
+ safetensors==0.5.3
45
+ scipy==1.15.3
46
+ semantic-version==2.10.0
47
+ setuptools==80.9.0
48
+ shellingham==1.5.4
49
+ six==1.17.0
50
+ sniffio==1.3.1
51
+ starlette==0.46.2
52
+ sympy==1.14.0
53
+ tokenizers==0.21.1
54
+ tomlkit==0.13.3
55
+ torch==2.7.1
56
+ tqdm==4.67.1
57
+ transformers==4.52.4
58
+ typer==0.16.0
59
+ typing-inspection==0.4.1
60
+ typing_extensions==4.14.0
61
+ tzdata==2025.2
62
+ urllib3==2.4.0
63
+ uvicorn==0.34.3
64
+ websockets==15.0.1