Download app from Baborok/DGA_test: direct link, hf CLI and curl.
- Browser
- Download file 5.25 kB
-
https://huggingface.co/Baborok/DGA_test/resolve/main/app
- Command line
-
hf download hf://Baborok/DGA_test/app
-
curl -L -o app https://huggingface.co/Baborok/DGA_test/resolve/main/app
5.25 kB
| import numpy as np | |
| from keras.models import load_model | |
| from numpy import random | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import matplotlib.animation as animation | |
| import datetime as dt | |
| import PySimpleGUI as sg | |
| from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg | |
| import gradio as gr | |
| model = load_model('model.h5') | |
| def transformer(Водород,Кислород,Азот,Метан,CO,CO2,Этилен,Этан,Ацетилен,Дибензилсульфид,Напряжение,Поверхностное_Н,Диэлектрическая_жесткость,Содержание_Воды,Срок_службы): | |
| data = np.array([[Водород,Кислород,Азот,Метан,CO,CO2,Этилен,Этан,Ацетилен,Дибензилсульфид,Напряжение,Поверхностное_Н,Диэлектрическая_жесткость,Содержание_Воды,Срок_службы]]) | |
| prediction = model.predict(data) | |
| x = int(prediction[0]) | |
| if x >= 56: | |
| transformer_index = f'Индекс состония трансформатора 1 с процентом оставшегося ресурса {x}' | |
| elif 29<=x<=55: | |
| transformer_index = f'Индекс состония трансформатора 2 с процентом оставшегося ресурса {x}' | |
| elif 17<=x<=28: | |
| transformer_index = f'Индекс состония трансформатора 3 с процентом оставшегося ресурса {x}' | |
| elif 6<=x<=16: | |
| transformer_index = f'Индекс состония трансформатора 4 с процентом оставшегося ресурса {x}' | |
| elif x<=5: | |
| transformer_index = f'Индекс состония трансформатора 5 с процентом оставшегося ресурса {x}' | |
| return transformer_index | |
| fig = plt.figure() | |
| ax = fig.add_subplot(1, 1, 1) | |
| xs = [] | |
| ys = [] | |
| def cock(): | |
| myArray = np.array([]) | |
| for n in range(1): | |
| a = random.randint(12886) | |
| b = random.randint(21800) | |
| c = random.randint(60600) | |
| d = random.randint(7406) | |
| e = random.randint(520) | |
| f = random.randint(2480) | |
| g = random.randint(16684) | |
| h = random.randint(1450) | |
| j = random.randint(164) | |
| k = random.randint(500)/100 | |
| l = random.randint(100) | |
| z = random.randint(60) | |
| x = random.randint(70) | |
| v = random.randint(30) | |
| transformer(a,b,c,d,d,e,f,g,h,j,k,l,z,x,v) | |
| myArray = np.append(myArray,x) | |
| return(myArray) | |
| def get_plot(period=1): | |
| temp_c=cock() | |
| xs.append(dt.datetime.now().strftime('%H:%M:%S.%f')) | |
| ys.append(temp_c) | |
| update = gr.LinePlot.update( | |
| value=pd.DataFrame({"x": xs, "y": ys}), | |
| xs="x", | |
| ys="y", | |
| title="Plot (updates every second)", | |
| width=600, | |
| height=350, | |
| ) | |
| return update | |
| def get_time(): | |
| return dt.datetime.now() | |
| with gr.Blocks() as demo: | |
| with gr.Row(): | |
| with gr.Column(): | |
| c_time2 = gr.Textbox(label="Current Time refreshed every second") | |
| gr.Textbox( | |
| "Change the value of the slider to automatically update the plot", | |
| label="", | |
| ) | |
| period = gr.Slider( | |
| label="Period of plot", value=1, minimum=0, maximum=10, step=1 | |
| ) | |
| plot = gr.LinePlot(show_label=False) | |
| with gr.Column(): | |
| name = gr.Textbox(label="Enter your name") | |
| greeting = gr.Textbox(label="Greeting") | |
| button = gr.Button(value="Greet") | |
| button.click(lambda s: f"Hello {s}", name, greeting) | |
| demo.load(lambda: dt.datetime.now(), None, c_time2, every=1) | |
| dep = demo.load(get_plot, None, plot, every=1) | |
| period.change(get_plot, period, plot, every=1, cancels=[dep]) | |
| if __name__ == "__main__": | |
| demo.queue().launch() | |
| #def animate(i, xs, ys): | |
| # Состояние трансформатора с текущего ридинга | |
| #temp_c = cock() | |
| # Добавляем значения на лист | |
| #xs.append(dt.datetime.now().strftime('%H:%M:%S.%f')) | |
| #ys.append(temp_c) | |
| # Лимит массивов | |
| #xs = xs[-20:] | |
| #ys = ys[-20:] | |
| # нарисовать хс yс | |
| #ax.clear() | |
| #ax.plot(xs, ys) | |
| # Format plot | |
| #plt.xticks(rotation=45, ha='right') | |
| #plt.subplots_adjust(bottom=0.30) | |
| #plt.title('Показатель Индекса трансформатора') | |
| #plt.ylabel('Индекс состояния трансформатора') | |
| #ani = animation.FuncAnimation(fig, animate, fargs=(xs, ys), interval=100) | |
| #def draw_figure(canvas, figure): | |
| #tkcanvas = FigureCanvasTkAgg(figure, canvas) | |
| #tkcanvas.draw() | |
| #tkcanvas.get_tk_widget().pack(side='top', fill='both', expand=1) | |
| #return tkcanvas | |
| #layout = [[sg.Text('Plot test')], | |
| #[sg.Canvas(key='-CANVAS-')], | |
| #[sg.Button('Ok')]] | |
| #window = sg.Window('Matplotlib In PySimpleGUI', layout, size=(715, 500), finalize=True, element_justification='center', font='Helvetica 18') | |
| #tkcanvas = draw_figure(window['-CANVAS-'].TKCanvas, fig) | |
| #event, values = window.read() | |
| #window.close() |