mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
demos
This commit is contained in:
parent
d073a5ec56
commit
0504c5750a
@ -151,11 +151,13 @@ def serve_files_in_background(interface, port, directory_to_serve=None, server_n
|
||||
if self.path == "/api/predict/":
|
||||
# Make the prediction.
|
||||
self._set_headers()
|
||||
print("in")
|
||||
data_string = self.rfile.read(
|
||||
int(self.headers["Content-Length"]))
|
||||
msg = json.loads(data_string)
|
||||
raw_input = msg["data"]
|
||||
prediction, durations = interface.process(raw_input)
|
||||
print("prediction")
|
||||
|
||||
output = {"data": prediction, "durations": durations}
|
||||
self.wfile.write(json.dumps(output).encode())
|
||||
@ -262,4 +264,4 @@ def url_ok(url):
|
||||
r = requests.head(url)
|
||||
return r.status_code == 200
|
||||
except ConnectionError:
|
||||
return False
|
||||
return False
|
||||
|
@ -1,8 +0,0 @@
|
||||
import gradio as gr
|
||||
import random
|
||||
|
||||
def upload(file):
|
||||
print(file.name)
|
||||
return "/mnt/c/Users/aliab/projects/gradio/gradio/static/js/interfaces/output/file.js"
|
||||
|
||||
gr.Interface(upload, "file", "file").launch()
|
17
demo/spectogram.py
Normal file
17
demo/spectogram.py
Normal file
@ -0,0 +1,17 @@
|
||||
import gradio as gr
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from scipy import signal
|
||||
from scipy.io import wavfile
|
||||
|
||||
|
||||
def reverse_audio(audio):
|
||||
sr, data = audio
|
||||
data = np.delete(data, 1, 1).reshape(-1)
|
||||
frequencies, times, spectrogram = signal.spectrogram(data.reshape(-1), sr, window="hamming")
|
||||
|
||||
plt.pcolormesh(times, frequencies, np.log10(spectrogram))
|
||||
return plt
|
||||
|
||||
|
||||
gr.Interface(reverse_audio, "audio", "plot").launch()
|
BIN
demo/tmp.zip
Normal file
BIN
demo/tmp.zip
Normal file
Binary file not shown.
15
demo/zip_to_json.py
Normal file
15
demo/zip_to_json.py
Normal file
@ -0,0 +1,15 @@
|
||||
import gradio as gr
|
||||
from zipfile import ZipFile
|
||||
|
||||
def zip_to_json(file_obj):
|
||||
files = []
|
||||
with ZipFile(file_obj.name) as zfile:
|
||||
for zinfo in zfile.infolist():
|
||||
files.append({
|
||||
"name": zinfo.filename,
|
||||
"file_size": zinfo.file_size,
|
||||
"compressed_size": zinfo.compress_size,
|
||||
})
|
||||
return files
|
||||
|
||||
gr.Interface(zip_to_json, "file", "json").launch()
|
10
demo/zip_two_files.py
Normal file
10
demo/zip_two_files.py
Normal file
@ -0,0 +1,10 @@
|
||||
import gradio as gr
|
||||
from zipfile import ZipFile
|
||||
|
||||
def zip_two_files(file1, file2):
|
||||
with ZipFile('tmp.zip', 'w') as zipObj:
|
||||
zipObj.write(file1.name, "file1")
|
||||
zipObj.write(file2.name, "file2")
|
||||
return "tmp.zip"
|
||||
|
||||
gr.Interface(zip_two_files, ["file", "file"], "file").launch()
|
Loading…
Reference in New Issue
Block a user