File size: 1,033 Bytes
78372f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
from fastapi import FastAPI
import gradio as gr
import asyncio, time
import psutil
import os
from threading import Thread
app = FastAPI()




def change_textbox():
    return gr.Textbox.update(visible=True)

@app.get("/memory")
def read_main():
    for exec_num in range(0, 1):
        X = [i for i in range(0, 9000000)]
                    
        memory_usage_dict = dict(psutil.virtual_memory()._asdict())
        memory_usage_percent = memory_usage_dict['percent']

        # current process RAM usage
        pid = os.getpid()
        current_process = psutil.Process(pid)
        current_process_memory_usage_as_KB = current_process.memory_info()[0] / 2.**20

        del X
    return { "0" : { "메모리" : f"{memory_usage_percent}%", "mykb" : f"{current_process_memory_usage_as_KB: 9.3f} KB" } }


def run():
    with gr.Blocks() as demo:
        gr.Markdown("Start")
        gr.mount_gradio_app(app, demo, path="/memory")
    demo.launch()
    



    

def keep_alive():
    server = Thread(target=run)
    server.start()