Solutions: Interpreter and FormFunction/APIFunction

Wolfram Cloud Platform

Carlo Barbieri, Riccardo Di Virgilio

Wolfram Research, Inc.

Solutions

1. Create a FormFunction that asks for a city and displays one piece of information about that city (current weather, population, time of sunset, coordinates…). Bonus points: make a page that displays tourist information in a nice grid (FormFunction[…, Grid[…], “HTML”])

CloudDeploy @ FormFunction["city" -> "City", Grid[{
	{"current temperature", WeatherData[#city, "Temperature"]},
	{"map", GeoGraphics[#city]},
	{"nicknames", #city(EntityProperty["nicknames", EntityProperty["City","Nicknames"], "EntityProperty[\"City\", \"Nicknames\"]"])}
}]&, "HTML"]

2. Create a form that uses at least three different controllers.

CloudDeploy @ FormFunction[{
	"Number" -> <|
		"Interpreter" -> Restricted["Number", {1, 100}],
		"Control" -> Slider
	|>,
	"AnotherNumber" -> <|
		"Interpreter" -> Restricted["Number", {1, 100}],
		"Control" -> InputField
	|>,
	"OneOfTheseNumbers" -> {1, 2, 3}
	},
	Identity
]

3. Create a FormFunction that is comes already filled with a random number and deploy it. Now try making a label that contains your country name, or the current date.

CloudDeploy @ FormFunction[{
	"Number" -> <|
		"Interpreter" -> Restricted["Number", {1, 100}],
		"Input" :> RandomInteger[{1, 100}]
	|>,
	"Date" -> <|
		"Interpreter" :> Restricted[
			"Date", {
				DateObject[], 
				Infinity
			}
		],
		"Input" :> DateString["Date"]
	|>,
	"Country" -> <|
		"Interpreter" -> "Country",
		"Input" :> CommonName @ First @ GeoIdentify["Country"]
	|>
	},
	Identity
]

4. Create an Instagram clone with a multistep form. First upload an image, second choose a filter, then return the filtered image. Bonus points for displaying a preview in the second step.

CloudDeploy @ FormFunction[{
	<|{"Image", None} -> "Image"|>,
	<|{"Filter", None} -> With[
		{rescaled = ImageResize[#Image, {75, Automatic}]}, {
		rescaled -> Identity,
		Blur[rescaled] -> Blur, 
		ColorNegate[rescaled] -> ColorNegate,
		Darker[rescaled] -> Darker,
		EdgeDetect[rescaled] -> EdgeDetect
	}]
	|> &
	},
	#Filter[#Image] &,
	"PNG",
	AppearanceRules -> <|
		"Title" -> "Wolfra(gra)m",
		"Description" -> "Amazing selfie processing :)"
	|>
]