| import gradio as gr | |
| import cv2 | |
| import cv2 | |
| import urllib.request | |
| import numpy as np | |
| # 图片url | |
| # url = 'http://114.96.110.174:6278/photo/11.jpg' | |
| url = 'http://aust001.pythonanywhere.com/photo/11.jpg' | |
| def to_black(text): | |
| if text=='love': | |
| # 从url中获取图片 | |
| resp = urllib.request.urlopen(url) | |
| image = np.asarray(bytearray(resp.read()), dtype="uint8") | |
| image = cv2.imdecode(image, cv2.IMREAD_COLOR) | |
| image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | |
| return image | |
| interface = gr.Interface(fn=to_black, inputs="text", outputs="image") | |
| interface.launch() |