CoolFace
Apppublic

CodeCrew/discord_bot

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
gra.py45 linesDownload Raw Back to root
1from fastapi import FastAPI2import gradio as gr3import asyncio, time4import psutil5import os6from threading import Thread7app = FastAPI()8 9 10 11 12def change_textbox():13    return gr.Textbox.update(visible=True)14 15@app.get("/memory")16def read_main():17    for exec_num in range(0, 1):18        X = [i for i in range(0, 9000000)]19                    20        memory_usage_dict = dict(psutil.virtual_memory()._asdict())21        memory_usage_percent = memory_usage_dict['percent']22 23        # current process RAM usage24        pid = os.getpid()25        current_process = psutil.Process(pid)26        current_process_memory_usage_as_KB = current_process.memory_info()[0] / 2.**2027 28        del X29    return { "0" : { "메모리" : f"{memory_usage_percent}%", "mykb" : f"{current_process_memory_usage_as_KB: 9.3f} KB" } }30 31 32def run():33    with gr.Blocks() as demo:34        gr.Markdown("Start")35        gr.mount_gradio_app(app, demo, path="/memory")36    demo.launch()37    38 39 40 41    42 43def keep_alive():44    server = Thread(target=run)45    server.start()