Spaces:
Runtime error
Runtime error
File size: 914 Bytes
c0ca216 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import gradio as gr
import sys
class Logger:
def __init__(self, filename):
self.terminal = sys.stdout
self.log = open(filename, "w")
def write(self, message):
self.terminal.write(message)
self.log.write(message)
def flush(self):
self.terminal.flush()
self.log.flush()
def isatty(self):
return False
sys.stdout = Logger("output.log")
def test(x):
print("This is a test")
print(f"Your function is running with input {x}...")
return x
def read_logs():
sys.stdout.flush()
with open("output.log", "r") as f:
return f.read()
with gr.Blocks() as demo:
with gr.Row():
input = gr.Textbox()
output = gr.Textbox()
btn = gr.Button("Run")
btn.click(test, input, output)
logs = gr.Textbox()
demo.load(read_logs, None, logs, every=1)
demo.queue().launch() |