Spaces:
Sleeping
Sleeping
File size: 2,631 Bytes
e72a183 2ce162e caab264 2ce162e caab264 2ce162e 6793464 2ce162e 6793464 2ce162e 6793464 2ce162e |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import os
os.system("pip install seaborn")
import gradio as gr
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Function to generate random visitor data
def generate_random_visitors(num_points):
return np.random.randint(0, 1000, size=num_points)
# Function to generate random energy distribution heatmap data
def generate_random_heatmap_data(size):
return np.random.rand(size, size) * 100
# Generate random visitor data
num_points = 24 # Assume 24 time points for a day
visitor_data = generate_random_visitors(num_points)
# Function to plot visitor data and heatmap
def plot_data(start_time, end_time, energy_algorithm):
# Convert start_time and end_time to integers
start_time = int(start_time)
end_time = int(end_time)
# Ensure start_time is less than end_time
if start_time > end_time:
return "开始时间点不能晚于结束时间点", None
# Generate visitor data for the selected time range
selected_data = visitor_data[start_time:end_time + 1]
# Plotting the visitor data line chart
fig, ax = plt.subplots(2, 1, figsize=(12, 10))
# Line chart for visitor data
ax[0].plot(range(start_time, end_time + 1), selected_data, marker='o')
ax[0].set_title("Line chart of the number of visitors to the exhibition hall")
ax[0].set_xlabel("time step")
ax[0].set_ylabel("Number of people")
# Generate heatmap data
heatmap_data = generate_random_heatmap_data(num_points)
# Heatmap for energy distribution
sns.heatmap(heatmap_data, cmap="YlOrRd", ax=ax[1], cbar=True)
ax[1].set_title("Energy distribution heat map of the exhibition hall")
plt.tight_layout()
plt.show()
return f"选择的能源调度算法是: {energy_algorithm}", fig
# Define Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# 展馆人流与能源分配分析")
with gr.Row():
with gr.Column():
start_time = gr.Slider(0, num_points - 1, 0, label="开始时间点")
end_time = gr.Slider(0, num_points - 1, num_points - 1, label="结束时间点")
energy_algorithm = gr.Dropdown(["自适应负载调度", "粒子群算法", "蚁群算法"], label="选择能源调度算法")
btn = gr.Button("生成图表")
with gr.Column():
output_text = gr.Textbox(label="选中的能源调度算法")
plot_output = gr.Plot(label="展馆人流数量折线图与能源分配热力图")
btn.click(plot_data, inputs=[start_time, end_time, energy_algorithm], outputs=[output_text, plot_output])
demo.launch()
|