abidlabs HF Staff commited on
Commit
c0ca216
·
1 Parent(s): cfeb03b

Create app.py

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