tadd first iteration of web interface - counterfacto - small software tool to analyze twitter and highlight counterfactual statements
HTML git clone git://parazyd.org/counterfacto.git
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit a6e2fee6da44bd214d6db79113be431142bb60bf
DIR parent c197f14a541519e2e261e6ff6bebbfaf742181d0
HTML Author: parazyd <parazyd@dyne.org>
Date: Mon, 2 Jan 2017 21:05:31 +0100
add first iteration of web interface
Diffstat:
M README.md | 15 +++++++++++++++
M counterfacto | 2 --
A counterfacto-web | 35 +++++++++++++++++++++++++++++++
A static/bootstrap.min.css | 7 +++++++
A static/js/jquery-3.1.1.min.js | 4 ++++
A static/js/search.js | 12 ++++++++++++
A static/jumbotron-narrow.css | 79 +++++++++++++++++++++++++++++++
A static/search.css | 38 +++++++++++++++++++++++++++++++
A templates/index.html | 34 +++++++++++++++++++++++++++++++
9 files changed, 224 insertions(+), 2 deletions(-)
---
DIR diff --git a/README.md b/README.md
t@@ -43,12 +43,27 @@ After installing the necessary python modules, run `make`, which will
then download the needed data for nltk, and tell you how to use your
twitter credentials in counterfacto
+### Running the web edition of counterfacto
+
+To run counterfacto along with its web interface, you will need
+additional dependencies:
+
+```
+python-flask
+```
+
## Usage
```
usage: ./counterfacto [-a account] [-f tweetfile] [-s searchterm]
```
+The web interface can be ran with (port defaults to 5000):
+
+```
+usage: ./counterfacto-web [-p port]
+```
+
## References
- [Learning Representations for Counterfactual InferenceĀ (2016)](http://jmlr.org/proceedings/papers/v48/johansson16.pdf)
DIR diff --git a/counterfacto b/counterfacto
t@@ -30,7 +30,6 @@ import sys
from twitter import *
import twokenize
-
global tweetfile
global taggedFile
taggedFile = 'tagged.txt'
t@@ -42,7 +41,6 @@ except:
print('no credentials file found. please create it.')
exit(1)
-
def main():
## credential check json
#print(api.VerifyCredentials())
DIR diff --git a/counterfacto-web b/counterfacto-web
t@@ -0,0 +1,35 @@
+#!/usr/bin/env python2
+
+from flask import Flask, render_template, request, json
+import os
+
+app = Flask(__name__)
+
+@app.route("/")
+def main():
+ return render_template('index.html')
+
+@app.route("/search", methods=['POST'])
+def search():
+ _name = request.form['inputName']
+ _method = request.form['searchMethod']
+
+ if not _name or not _method:
+ return "Wrong data. Please try again."
+
+ if _method == "account":
+ os.system("./counterfacto -a " + _name)
+ elif _method == "searchterm":
+ os.system("./counterfacto -s " + _name)
+
+if __name__ == "__main__":
+ try:
+ if sys.argv[1] == '-p':
+ _port = sys.argv2
+ except:
+ _port = 5000
+
+ app.run(
+ host="0.0.0.0",
+ port=int(_port)
+ )
DIR diff --git a/static/bootstrap.min.css b/static/bootstrap.min.css
t@@ -0,0 +1,6 @@
+/*!
+ * Bootstrap v3.3.7 (http://getbootstrap.com)
+ * Copyright 2011-2016 Twitter, Inc.
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
parazyd.org:70 /git/counterfacto/commit/a6e2fee6da44bd214d6db79113be431142bb60bf.gph:118: line too long