import gradio as gr def greet(name): return "Hello " + name + "!!" iface = gr.Interface(fn=greet, inputs="text", outputs="text") iface.launch() Text to image AI, python import datetime import time from skimage import io, color from PIL import Image from io import BytesIO from skimage.io import imread, imsave import imutils # Location of files on your system PATH_TO_FILES = '/home/ekene/Documents/working/ChoiceData/imglb2017/' # Start by importing modules from glob import glob import cv2 import datetime import sys import os import string import warnings from os.path import join import matplotlib.pyplot as plt def main(argv): timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S%f") print("Initialising...") if len(argv) == 2: filename = argv[1] full_path = PATH_TO_FILES + filename img = imread(full_path) scale_image = 2 # downscale the image img = cv2.resize(img, (scale_image, scale_image)) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #otsu = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU) #img = cv2.cvtColor(otsu, cv2.COLOR_GRAY2BGR) # Apply histogram equalization h, w = gray.shape[:2] cv_he = cv2.equalizeHist(gray) #cv2.imshow('HE', cv_he) ualized image _, contours, hierarchy = cv2.findContours(cv_he, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) ntourSeparation=(20,20)) # sort contours by contour area # keep only contours that are larger than 10% of the image area # (here we assume the largest contour will be around the "head") filtered_contours = [c for c in contours if cv2.contourArea(c) > 1000] #calculate distance between each contour and sort contours by distance # print(filtered_contours, contours) closest_contours = sorted(filtered_contours, key = cv2.contourArea, reverse=True) closest_contours = closest_contours[:4] # selected_contours = closest_contours # sort by smallest contour area #filtered_contours = sorted(filtered_contours, key = cv2.contourArea, reverse=True) # used for testing if len(filtered_contours) > 1: return 0 cv2.drawContours(gray, [filtered_contours[0]], -1, (255,255,255), 2) cv2.drawContours(gray, filtered_contours, -1, (255,255,255), 2) cv2.imshow("search by smallest area", gray) cv2.waitKey(0) return 0 # adding to show a function image def show_image(frame): plt.subplot(1,2,1) plt.title('Original Image') plt.imshow(frame, cmap='gray') plt.subplot(1,2,2) plt.title('Image with contours drawn') plt.imshow(frame, cmap='gray') plt.show() return 0 def image_face_detection(path_to_image): # Initialise the trackbar cv2.namedWindow('Frame') cv2.namedWindow('Threshold') current_image = cv2.imread(path_to_image) frame = current_image # threshold_trackbar = cv2.createTrackbar('Threshold', 'Frame', 51, 255, nothing) # cv2.createTrackbar('Threshold', 'Frame', 100, 255, nothing) # cv2.createTrackbar('Threshold', 'Frame', 130, 255, nothing) # cv2.createTrackbar('Threshold', 'Frame', 150, 255, nothing) # cv2.createTrackbar('Threshold', 'Frame', 90, 255, nothing) # cv2.createTrackbar('Threshold', 'Frame', 180, 255, nothing) #cv2.namedWindow("Frame") #cv2.createTrackbar('Threshold', "Frame", 50, 255, nothing) # Initialize the first frame, resize the window, start the timer # first_time = True first_time = True # start_clock = time.time() # main_loop() # print('Run time ', time.time()-start_clock) start_clock = time.time() # Capture keyboard events key = cv2.waitKey(1) & 0xFF # Press space to pause or unpause the video