Access html drag and drop with python - python

I have found a very nice algorithm for image classification (https://everypixel.com/aesthetics) and was wondering if its possible to upload image files to the webpage with python. They are using a drag and drop system for the image files. Because the algorithm tags those uploaded pictures, the possibility of automatic upload would be very nice.

Python is just a language and not a framework. This means it is not sufficient to be a web server(something that will accept a request and respond to it).
So you need to use a server like flask to accept the request and implement your algorithm there.To attach a file you need to implement a frontend as well.

Related

Creating a web app in django that creates a video (with moviepy) and plays it: Where to start?

I would like to make a web application where a user can:
click a button on a webpage to create a **random video (with moviepy)
play that video back on the webpage
click the button again to create a new **random video that replaces the existing one
** The random video will be created with a python/moviepy script that downloads a bunch of random video clips from the internet to a directory on my computer. It then compiles them into one video (.mp4 file).
I've done the python script bit already which successfully creates the video file.
To make the web app bit I have been recommended django and that's where I'm stuck!
So far I have installed django and got to grips with the basics .. I have a home page that says "Hello world".
My question is where do I go from here?
How do I connect my python/moviepy script with django?
What steps, apps, components etc, within django should I look into to make this thing?
I'm new to coding and looking for some guidance.
Thanks!
If you create a model with FileField then your moviepy script should upload videos into that field, that field can save the video in a specified directory in MEDIA_ROOT(you can store your post based on date) then that field will store the URL to it (you need to specify MEDIA_URL in settings.py). You can define some sort of IDs to them, if video privacy is not important, then you can use the model IDs. These IDs can be obtained trough Path converters .
At the client-side, javascript is needed. Simply running the script in view is possible, but then the user will need to wait for the response (and the browser should run into time-out).
You should look at server-sent events. With Vue.js you can easily display a loading element while waiting for the event (a video to be generated) and then download and switch to the video (see Django CRUD application tutorials). The python script can run asynchronously (you call it in the view).
It is a lot, I know.
Actually I'm going to learn these now, sorry for mistakes.
As I see, Django is for complex sites, you should look for Flask instead.
(I am learning Django and I know nothing about Flask, so I`ll go with it)
Here is the needed setup:
define the urlpatterns for handling the URLs
create a model for storing your video
create a django template for your page (html)
define a view for rendering out the template (passing the video)
maybe some css to design it
You can run your video generator(in the view) at every reload and override existing video(in this case you don't even need a model) or you can save the generated videos and capture the IDs in the URLs (for example: https://yoursite.com/1), in this case, the videos remain shareable.
If you go with the first option and sharing videos is not important for you then you could write a simple html page with a video and a button. The button can trigger a javascript function to run the video generator python script and refresh the page(the video is overridden), you may need to wait to the script otherwise the old video can load.
Restful API is a more advanced way to refresh the video, without reloading the page.
After these, you can deploy your page using an Apache server for example.
I tried to give you some guidelines (I am learning this on my own)
Hope that it helped :) There are tutorials for these.

Upload stock images Appium iOS Simulator

My application allows for users to upload a picture of themselves. The iOS simulator comes with stock images. How would I go about using one of those stock images for the image upload?
After clicking on the element that allows for users to upload images I receive the iOS popup:
I select "Album" but when using the Appium inspector it does not allow any access to these images, I am not able to select any (as seen in the screenshot)
I doubt if its possible to parse this screen since its already other app: Photos app.
With Appium you can interact only with the app that is signed same certificate as WebDriverAgent. At least its valid for real devices, but since you are not able to parse with Appium Desktop my guess its still the same for simulator.
You might try to use TouchAction/tap by coordinates (less stable, but quick way to go) or have integrate image recognition library, e.g. sikuli in your code (more work, but clearly more stable) to select images in Photos app

Can I post an image file on the public web server with python?

I have a python program that draws a physical network topology from gns3 using CDP and saves it after every 1 minute as a .png image file. I'm wondering if there is a way to post that image in a some kind of web-server so that I would be able to access it remotly with browser. Thank you
If the web server is running locally, all you need is to save it to the right directory.
If you have a web space somewhere, you can use FTP for uploading as described for example in this previous question.
You can also upload it directly to some image hosting web service, where you could then use their UI to nicely browse, categorize or delete the images as required -- you could look at some open source image uploading script like uimge for inspiration.

How to Combine Html + CSS code with python function?

I have zero experience with website development but am working on a group project and am wondering whether it would be possible to create an interaction between a simple html/css website and my python function.
Required functionality:
I have to take in a simple string input from a text box in the website, pass it into my python function which gives me a single list of strings as output. This list of strings is then passed back to the website. I would just like a basic tutorial website to achieve this. Please do not give me a link to the CGI python website as I have already read it and would like a more basic and descriptive view as to how this is done. I would really appreciate your help.
First you will need to understand HTTP. It is a text based protocol.
I assume by "web site" you mean User-Agent, like FireFox.
Now, your talking about an input box, well this will mean that you've already handled an HTTP request for your content. In most web applications this would have been several requests (one for the dynamically generated application HTML, and more for the static css and js files).
CGI is the most basic way to programmatically inspect already parsed HTTP requests and create HTTP responses from objects you've set.
Now your application is simple enough where you can probably do all the HTTP parsing yourself to gain a basic understanding of what's going on, but you will still need to understand how to develop a server that can listen on a socket.
To avoid all that just find a Python application server that has already implemented all of the above and much more. There are many python application servers to choose from. Use one with a small learning curve for something as simple as above. Some are labeled as "micro-frameworks" in this genre.
Have you considered creating an app on Google App Engine (https://developers.google.com/appengine/)?
Their Handling Forms tutorial seems to describe your problem:
https://developers.google.com/appengine/docs/python/gettingstartedpython27/handlingforms

Python: upload images

Can python upload images onto the internet and provide a URL for it? For example is it possible for python to upload an image onto photobucket or any other uploading image service and then retreive the URL for it?
Certainly. You'll need to find an image hosting service with an API (hint: Flickr), and then write some Python code to interact with it (hint: XML-RPC).
Pseudocode
import xmlrpclib
with open( "..." ) as imagelist:
for image in imagelist:
message = xmlrpclib.make_some_message_or_other
response = message.send( )
response.parse( )
You'll need a more specific question if you want a more specific answer!
Sure!
To do it, you basically have to have Python pretend to be a web browser. You need to go get the upload form, fill in all the fields, and pick your image. Then you need to submit the form data, uploading the image. Once that's done, you need to get the "upload complete" page from the site, and find the URL where the image went.
A good library to start with might be the Python version of Perl's famous WWW::Mechanize module. The library is basically a programmable Web browser that you can script in Python.
EDIT: If you plan to do this a lot, you probably do want to use an actual supported API. Otherwise the image hoster might get mad that your python bot is spamming their site.

Categories

Resources