Is there any way to share images between two streamlit webapps? - python

I want to link 2 web pages made using streamlit and hosted using Heroku. One of them removes the image background and the other does an image classification task. (They could not be made into one due to slug size limits of Heroku). At present, the user has to manually download the segmented image from one webpage and upload it to the second webpage.
The 2 can be shown together using an HTML iframe tag but I am not able to figure out how to transfer the segmented image from one webpage to other.
Any suggestion or help will be appreciated
Also please prefer solutions using python and its frameworks as the whole project is in python and learning javascript, HTTP, etc will take some time.
(but if it's not possible using python, answers using other methods will also be welcome)

One of my seniors advised me to explore other hosting options. (I had seen an online tutorial using Heroku , and did not know much about others). It turns out that streamlit cloud provides a much larger slug size and allows you to host it for free if you open source your project(I had no issue doing so), so I have combined the two parts and am now hosting using streamlit cloud.

Related

How to best share updated html and csv files created in a Juypter notebook with colleagues

What exactly I am doing: updating a predictive model with new data bi-weekly, and then updating the csv file and plotly graphs (html files) that contain the new predictions
What my problem is: right now I am sharing these updated predictions either ad hoc over email or by uploading the files to google drive (or my often both). Neither is a very good solution so I am looking for a better way to programmatically update these files and share them with my colleagues
My ideal solution: a link I could share that would open a web page with all of this data updated. The link could either be something that you can't find without being given the exact link or something that required a username and password to access
Decent enough with python for data analysis and visualization but no experience deploying web apps. Thanks in advance

Django / Geodjango / Raster / geotiff: Problems with practice task

I got a practice task, which I can not get any further.
The task is the following:
Project Description The goal of the projects is to create a map view
similar to the Google Maps, where the user can see some imagery data
captured by drones.
User should be able to move around the map freely, as well as zoom in
and zoom out to take a closer look at the captured imagery data.
It is strongly desired that the served imagery data will support
transparency while minimizing the file size and bandwidth usage. This
does not have to be implemented, but solution ideas are welcomed.
The raw imagery data will be provided as GeoTIFF files. Imagery
visible on the map can be added by placing a file inside a directory
that is read by the server. Project Delivery Method
Project should be delivered as a Git repository with documentation
required to setup and run the project.
Requirements
1. Server implementation in Python 3.5+
2. Project must be able to run on Ubuntu Server 16.04
3. Optimal disk space usage for imagery data displayed to the user (as the app may be processing terabytes of satellite imagery data)
4. Relatively conservative bandwidth usage
Notes:
1. The project will be deployed on a machine that is already running other Python software. Dependency conflicts must be avoided.
(virtualenv, Docker)
2. The UI can be a simple HTML page with embedded libraries and inline scripts.
In addition, it was specified in an e-mail:
"The test task is not code but just the approach and rough app
architecture
```I'm attaching a tank spec. Like I've mentioned. I'm more interested
in problem-solving and your ideas. I expect a working prototype tough.
Use any libraries you wish to use. Create an elegant, easy to
understand the solution. You can use as much time as you want. Would be
great if you could deliver the code by git.... ```"
So far I have done:
Ubuntu as VM
Venv
Postgres and PostGIS installed (Django writes error-free in a database)
Django project and app created
Documentation up to this point
I have now integrated the geotiff via console and that seems to work too:
from django.contrib.gis.gdal import GDALRaster
raster = GDALRaster('base/static/base/geotiff/xto-site3-rgb.tif')
raster.name
Out[4]: 'base/static/base/geotiff/xto-site3-rgb.tif'
raster.width, raster.height
Out[5]: (23001, 9668)
In the models.py is so far:
from django.contrib.gis.db import models
class RasterBase(models.Model):
raster = models.RasterField()
name = models.TextField()
How does it work that I install the grid so that I can portray this in an html similar to google maps? If I understand correctly, I must now write the geotiff in the database, and read on from there, right?
Unfortunately, I find in the network largely only outdated stuff, or often examples, which is assumed by shapefiles. Should I convert the grid to a shapefile and continue like that?
So far, I only make small things in Django, like my own blog and a few statistics, but this with Geodjango is a bit fierce because I have to give it up, as it were tomorrow. Latest Tuesday morning.
I would be very grateful if someone could give me some tips. All in all, that's pretty important to me, and it would be a shame if I messed up half of the task (or the last third) of the task.
Django is version 2.0
The GeoTIFF ~900mb
Thanks for all. :-)
Late to the party, but maybe some people are searching for a solution here.
When you want to display geodata on a map, you can use a WebGIS framework like Openlayers or Leaflet. They provide all the functionality to move the map and zoom in / out.
I would not recommend to store large raster data in a database. You can serve it directly from a file server via a TileLayer or use a XYZ tiling structure to minimize the bandwidth usage.
Openlayers has a lot of examples on how to server GeoTiff files.

Image Optimization (Google App Engine with Python)

I haven't found a similar question that I'm looking for Image Optimization.
I've tested how much Facebook can optimize the image uploaded:
980KB --> 77KB
846KB --> 62.1KB
From what I found out, Facebook is capable of optimizing the image up to 10 times while still pertaining some minimum image quality, as for the test above.
So, can anyone share what are the best ways that you have implemented to optimize image uploaded by user ?
When I searched in internet, I've seen some websites offer paid service for image optimization. However, we prefer not to subscribe for any paid service for image optimization at this stage.
I'm developing the project with Python language within Google App Engine environment. Any part where we can reuse from Python libraries or even Google App Engine libraries to achieve so ?
Probably you should star this issue to get pngcrush like functionality added to the AppEngine images API.
Basic optimization boils down to:
Choosing the appropriate format for the image (usually jpeg for
photographs; you can use jpeg across the board if you're not
concerned about image quality but otherwise png for screenshots etc.
may be wise)
Reducing the image to the smallest resolution appropriate for your
application
Increasing the compression level to the highest level possible while
maintaining your quality standards
You can also nitpick by stripping extraneous metadata, but that is usually unnecessary and not desirable.
If you want to do all of this in an automated fashion, you'll have to set a standard format and compression level across the board and accept that it won't be perfect in all cases, or else be able to determine what settings are appropriate for the image programmatically (which is quite difficult, unless you simply ask your users at upload time directly).
Normally I would use ImageMagick via the PythonMagick bindings for this task, but that may not be feasible on Google Apps Engine. In that case, maybe look at the Python Imaging Library.
Another solution is to use a 3rd party api, in this case you can use tinyPNG. There compression algorithm is probably one of the best out there. Check there developer guide here ~>
https://tinypng.com/developers
The first 500 photos per month are free & it's like $0.009 per image (> 500 && < 9500) or $0.002 > 10000 images.
You can't use PythonMagick unfortunately. But Python Imaging Library can be installed, and see Google Imaging Service on how to use it.
There is no magic bullet facebookesque optimization. You will have to try to develop your own that meets the standards you need. Most images these days are 5mp and up resizing them to 1280x720 or less is normal in web sites. The ability to crop extraneous image is also desirable before resizing.

Using Django as a map source for openlayer UI

I am thinking of creating a web application that shows a map of a city (from openstreetmaps data). I would like to create a layer on top which represents markers. I foresee that I will have a database of numerous markers, which will be shown on the map as layer. I have come across openstreetmap, openlayers, geodjango etc but am unable to figure out how to make all these fit together to solve my issue. I am comfortable using Django and Python. Can someone help me understand the following:
How to host OSM data on my own server using Django and acting as a Mapserver (or map source) for openlayers?
How to ask openlayer to talk to this server to render the map or overlays?
I'm sorry if some part of my question does not make sense; it is because my understanding how these components is quite hazy at the moment.
Displaying markers at coordinates is the easy part. The harder part is hosting your own base map. Here is one way I think you could do it:
Obtain the OpenStreetMap data for the area you are interested in.
Develop a stylesheet for your map, or use an existing one. Mapnik is an option.
Use Tilecache to serve cached image tiles of the map at various scale levels. This would have to run in addition to your django app.
Another option would be to use Tiledrawer to set up an Amazon EC2 server serving your base map without having to manually configure everything.
Stack Overflow is only letting me post two links, so you will have to search for the websites of Tilecache and Mapnik, but they are easy to find.
References:
https://gis.stackexchange.com/questions/10162/how-to-set-up-an-osm-server-with-tilecache-and-mapnik

Retrieving media (images, videos etc.) from links in Perl

Similar to Reddit's r/pic sub-reddit, I want to aggregate media from various sources. Some sites use OEmbed specs to expose media on the page but not all sites do it. I was browsing through Reddit's source because essentially they 'scrape' links that users submit, retrieve images, videos etc. They create thumbnails which are then displayed along the link on their site. Now, I would like to do something similar and I looked at their code[1] and it seems that they have custom scrapers for each domain that they recognize and then they have a generic Scraper class that uses simple logic to get images from any domain (basically they retrieve the web-page, parse the html and then determine the largest image on the page which they then use to generate a thumbnail).
Since it's open source I can probably reuse the code for my application but unfortunately I have chosen Perl as this is a hobby project and I'm trying to learn Perl. Is there a Perl module which has similar functionality? If not, is there a Perl module that is similar to Python Imaging Library? It would be handy to determine the image sizes without actually downloading the whole image & thumbnail generation.
Thanks!
[1] https://github.com/reddit/reddit/blob/master/r2/r2/lib/scraper.py
Image::Size is the specialised module for determining image sizes from various format. It should be enough to read the first 1000 octets or so from a resource, enough for the diverse image headers, into a buffer and operating on that. I have not tested this.
I do not know any general scraping module that has an API for HTTP range requests in order to avoid downloading the whole image resource, but it is easy to subclass WWW::Mechanize.
Try PerlMagick, installation instruction is also listed there.

Categories

Resources