File size: 1,673 Bytes
c5b702e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e184c49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93ef148
e184c49
c5b702e
 
 
 
 
 
e184c49
 
 
c5b702e
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
"""
Gradio Twitter analizer application.

This module provides a gradio-based web application
for the Twitter analyzer project.
"""
import gradio as gr

from tweet_scraper import retrieve_tweet_text
from backend import predict_positivity


def process_tweet(url: str) -> str:
    """
    Get a tweet's positivity.

    Args:
        url (str): Tweet's URL.

    Returns:
        str: Predicted positivity
    """
    text = retrieve_tweet_text(url)
    outcome = predict_positivity(text)

    return outcome
    
title = "Twitter Positivity Analyzer"
description = """
<h2> Description </h2>
Twitter is a social media network on which users post and interact with messages known as "tweets". It allows an user to post, like, and retweet tweets.  

Twitter is also known by the excessive negativity or criticism by a great part of its users. Considering that, this application intends to classify a tweet according to its positivity. The positivity is measured in five categories:
- Extremely negative
- Negative
- Neutral
- Positive
- Extremely positive

The application is based on a BERT model fine tuned on the [Coronavirus tweets NLP dataset](https://www.kaggle.com/datasets/datatattle/covid-19-nlp-text-classification).
"""

article = "Check out this [github repository](https://github.com/hectorLop/Twitter_Positivity_Analyzer) \
 with a lot more details about this method and implementation."


app = gr.Interface(
    fn=process_tweet,
    inputs=gr.inputs.Textbox(lines=2, placeholder="Tweet url..."),
    outputs="text",
    title=title,
    description=description,
    article=article,
)

if __name__ == "__main__":
    app, local_url, share_url = app.launch()