mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-06 10:25:17 +08:00
flag returns csv instead txt
This commit is contained in:
parent
01c07b4816
commit
0ae64c43bb
@ -9,9 +9,18 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The autoreload extension is already loaded. To reload it, use:\n",
|
||||
" %reload_ext autoreload\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%load_ext autoreload\n",
|
||||
"%autoreload 2\n",
|
||||
@ -23,7 +32,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -39,7 +48,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -54,7 +63,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 14,
|
||||
"metadata": {
|
||||
"scrolled": false
|
||||
},
|
||||
@ -63,9 +72,10 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Closing existing server...\n",
|
||||
"NOTE: Gradio is in beta stage, please report all bugs to: contact.gradio@gmail.com\n",
|
||||
"Model is running locally at: http://localhost:7860/\n",
|
||||
"Model available publicly for 8 hours at: https://c0097190.gradio.app/\n"
|
||||
"Model is running locally at: http://localhost:7861/\n",
|
||||
"Unable to create public link for interface, please check internet connection or try restarting python interpreter.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -75,30 +85,48 @@
|
||||
" <iframe\n",
|
||||
" width=\"1000\"\n",
|
||||
" height=\"500\"\n",
|
||||
" src=\"http://localhost:7860/\"\n",
|
||||
" src=\"http://localhost:7861/\"\n",
|
||||
" frameborder=\"0\"\n",
|
||||
" allowfullscreen\n",
|
||||
" ></iframe>\n",
|
||||
" "
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.lib.display.IFrame at 0x22abbdace10>"
|
||||
"<IPython.lib.display.IFrame at 0x26c65349978>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"''"
|
||||
]
|
||||
},
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"io.launch(inline=True, inbrowser=False, share=True, validate=False);"
|
||||
"io.launch(inline=True, inbrowser=False, share=True, validate=False)\n",
|
||||
";"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.6 (tensorflow)",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "tensorflow"
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
@ -110,7 +138,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.7"
|
||||
"version": "3.7.1"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
@ -9,6 +9,7 @@ from gradio import preprocessing_utils, validation_data
|
||||
import numpy as np
|
||||
from PIL import Image, ImageOps
|
||||
import datetime
|
||||
import csv
|
||||
|
||||
# Where to find the static resources associated with each template.
|
||||
BASE_INPUT_INTERFACE_TEMPLATE_PATH = 'templates/input/{}.html'
|
||||
@ -110,7 +111,7 @@ class Sketchpad(AbstractInput):
|
||||
timestamp = datetime.datetime.now()
|
||||
im.save(f'gradio-flagged/{timestamp.strftime("%Y-%m-%d %H-%M-%S")}.png', 'PNG')
|
||||
return None
|
||||
|
||||
|
||||
|
||||
class Webcam(AbstractInput):
|
||||
def __init__(self, preprocessing_fn=None, image_width=224, image_height=224, num_channels=3):
|
||||
@ -202,13 +203,20 @@ class ImageUpload(AbstractInput):
|
||||
array = im.reshape(1, self.image_width, self.image_height, self.num_channels)
|
||||
return array
|
||||
|
||||
def rebuild_flagged(self, inp):
|
||||
def rebuild_flagged(self, msg):
|
||||
"""
|
||||
Default rebuild method to decode a base64 image
|
||||
"""
|
||||
inp = msg['data']['input']
|
||||
im = preprocessing_utils.encoding_to_image(inp)
|
||||
timestamp = datetime.datetime.now()
|
||||
im.save(f'gradio-flagged/{timestamp.strftime("%Y-%m-%d %H-%M-%S")}.png', 'PNG')
|
||||
f = open('gradio-flagged/gradio-flagged.csv','a+')
|
||||
fields = [timestamp.strftime("%Y-%m-%d %H-%M-%S"),msg['data']['output']]
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(fields)
|
||||
f.close()
|
||||
|
||||
return None
|
||||
|
||||
class CSV(AbstractInput):
|
||||
|
@ -136,7 +136,7 @@ class Interface:
|
||||
f.write(str(msg['data']))
|
||||
f.close()
|
||||
inp = msg['data']['input']
|
||||
self.input_interface.rebuild_flagged(inp)
|
||||
self.input_interface.rebuild_flagged(msg)
|
||||
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user