[PYTHON] Web application that analyzes morphological elements and generates sentences with Markov chains [bottle]

Until now, I've done quite a lot of morphological analysis and Markov chains to generate sentences, I made it using a bottle.

views.html



<form method="GET" action="/show">
<p class="in">What are you talking about today?</p>
<p><input type="text" name="send_word"></input></p>
<p><input type="submit" value="Send"></p>
</form>

Add form submission to the HTML file to be called as the main screen.

style.css



input[type=submit]{
   border-radius: 5px;
   -moz-border-radius: 5px;
   -webkit-border-radius: 5px;
   -o-border-radius: 5px;
   -ms-border-radius: 5px;
   border:#a9a9a9 1px solid;
   -moz-box-shadow: inset 0 0 5px rgba(0,0,0,0.2),0 0 2px rgba(0,0,0,0.3);
   -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2),0 0 2px rgba(0,0,0,0.3);
   box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2),0 0 2px rgba(0,0,0,0.3);
   width:100%;
   height:40px;
   padding:0 3px;
   cursor:pointer;
   color:#333;
   font-weight:bold;
   background:#f5f5f5;
   text-shadow:1px 1px 0px #fff;
}

input[type=text]{
   border-radius: 5px;
   -moz-border-radius: 5px;
   -webkit-border-radius: 5px;
   -o-border-radius: 5px;
   -ms-border-radius: 5px;
   border:#a9a9a9 1px solid;
   -moz-box-shadow: inset 0 0 5px rgba(0,0,0,0.2),0 0 2px rgba(0,0,0,0.3);
   -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2),0 0 2px rgba(0,0,0,0.3);
   box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2),0 0 2px rgba(0,0,0,0.3);
   width:100%;
   height:30px;
   padding:0 3px;
}

input[type=text]:focus {
   border:solid 1px #20b2aa;
}

input[type=text], select { 
   outline: none;
}

When customizing buttons and text forms with CSS.

show.html


<h4 class="center">keyword{{send_word}}Markov!</h4>
<p>{{twits}}</p>

The HTML for displaying the result is like this, and the variable defined in bottle is inserted.

route.py


@route("/show", method="GET")
def send_word():
	send_word = request.query.send_word
	send_word.encode("utf-8")
	if send_word:
		
	
		os.remove("static/tweet.txt")

Receive by GET from the form with bottle. As usual, I save the search for the keyword in the text once, but I don't want to increase it, so delete it every time I execute it.

@error(500)
def error500(error):
	return template("500")

If the search word is a niche or the API limit appears, there will be a 500 error, so bottle will be used to escape. I wish I could separate the processing by status code with try except.

The rest is the same as the one I wrote before. I threw the finished product to Heroku with Dropbox deployment without using git.

http://markov-twit.herokuapp.com/

I made something like this.

Recommended Posts

Web application that analyzes morphological elements and generates sentences with Markov chains [bottle]
[Python] A quick web application with Bottle!
Parse and visualize JSON (Web application ⑤ with Python + Flask)
Try morphological analysis and Markov chains with Django (Ari with a lot of room for improvement)
Create a web application that recognizes numbers with a neural network
Web application with Python3.3.1 + Bottle (1) --Change template engine to jinja2