Spaces:
Sleeping
Sleeping
add file reader
Browse files
app.py
CHANGED
|
@@ -38,6 +38,14 @@ def net_info():
|
|
| 38 |
pass
|
| 39 |
return "\n".join(parts)
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
with gr.Tab("Fetch"):
|
| 43 |
url_in = gr.Textbox(label="url")
|
|
@@ -52,4 +60,9 @@ with gr.Blocks() as demo:
|
|
| 52 |
net_out = gr.Textbox(label="net")
|
| 53 |
net_btn.click(net_info, None, net_out)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
demo.launch()
|
|
|
|
| 38 |
pass
|
| 39 |
return "\n".join(parts)
|
| 40 |
|
| 41 |
+
|
| 42 |
+
def read_file(path):
|
| 43 |
+
try:
|
| 44 |
+
with open(path, 'r') as f:
|
| 45 |
+
return f.read()[:5000]
|
| 46 |
+
except Exception as e:
|
| 47 |
+
return 'Error: ' + str(e)
|
| 48 |
+
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
with gr.Tab("Fetch"):
|
| 51 |
url_in = gr.Textbox(label="url")
|
|
|
|
| 60 |
net_out = gr.Textbox(label="net")
|
| 61 |
net_btn.click(net_info, None, net_out)
|
| 62 |
|
| 63 |
+
with gr.Tab("File"):
|
| 64 |
+
file_in = gr.Textbox(label="path")
|
| 65 |
+
file_out = gr.Textbox(label="content")
|
| 66 |
+
file_in.submit(read_file, file_in, file_out)
|
| 67 |
+
|
| 68 |
demo.launch()
|