samples/twitter-sentiment-processor/demos/py-demo
Charlie Stanley 2c493f23bf
Update twitter python demo for 1.0.0 (#50)
2021-02-17 16:07:53 -08:00
..
processor Update twitter python demo for 1.0.0 (#50) 2021-02-17 16:07:53 -08:00
provider Update twitter python demo for 1.0.0 (#50) 2021-02-17 16:07:53 -08:00
viewer Update twitter python demo for 1.0.0 (#50) 2021-02-17 16:07:53 -08:00
README.md Update twitter python demo for 1.0.0 (#50) 2021-02-17 16:07:53 -08:00
local_secrets.json Initial commit of twitter processing pipeline sample using python-sdk (#37) 2020-12-04 18:14:39 -08:00
overview.png Initial commit of twitter processing pipeline sample using python-sdk (#37) 2020-12-04 18:14:39 -08:00
ui.png Initial commit of twitter processing pipeline sample using python-sdk (#37) 2020-12-04 18:14:39 -08:00

README.md

Twitter Sentiment Processor

Sample info

Attribute Details
Dapr runtime version v1.0.0+
Dapr Python SDK v1.0.0+
Language Python
Environment Local

Overview

This demo is an implementation of the Twitter Processing Pipeline demo in Python, using Dapr's Python SDK. The purpose of this demo is to showcase Dapr in Python.

Overview

Requirements

Set Twitter and Azure Cognitive Services credentials in the secrets file local_secrets.json:

{
    "Twitter": {
        "ConsumerKey": "",
        "ConsumerSecret": "",
        "AccessToken": "",
        "AccessSecret": ""
    },
    "Azure": {
        "CognitiveAPIEndpoint": "https://<service_name>.cognitiveservices.azure.com/",
        "CognitiveAPIKey": "<Service Api Key>"
    }
}

Undersanding the Pipeline

Provider

Provider service will receive Twitter feeds, invoke the processor application above, then save the results to state store and finally publishes to processed-tweets topic.

Used building blocks

Processor

Processor service exposes sentiment-score method which Provider service to invoke via service invocation. This receives a text and a language code from tweet payload and extract the sentiment and score for the text via Azure cognitive service.

Used building blocks

Viewer

Viewer app is a Flask web application serving web service. flask-SocketIO is used to enable real-time update tweets on the web page. This creates subscription to processed-tweets topic and broadcast tweet message from the topic to webpage via socket.io

Used building blocks

  • Pub Sub - is used to subscribe to processed-tweets topic. tweets can be displayed on the tweet sentiment on webpage. PubSub is defined in viewer/components/pubsub.yaml

Running

First, run the processor app:

cd processor
pip3 install -r requirements.txt
dapr run \
    --app-id tweet-processor \
    --app-port 3002 \
    --app-protocol grpc \
    --components-path ./components \
    python3 processor.py

In another terminal, run the provider app:

cd provider
pip3 install -r requirements.txt
dapr run \
    --app-id tweet-provider \
    --app-port 3001 \
    --app-protocol grpc \
    --components-path ./components \
    python3 provider.py

Finally, open another terminal and run the web UI app:

cd viewer
pip3 install -r requirements.txt
dapr run \
    --app-id tweet-viewer \
    --app-port 8083 \
    --app-protocol http \
    --components-path ./components \
    python3 viewer-server.py

Now, open the browser on http://localhost:8083/. You should see a web UI like this:

Web UI