Liu Yiwen commited on
Commit
266b4a6
·
1 Parent(s): 4570f48

删除了一些调试文件

Browse files
Files changed (5) hide show
  1. data.py +0 -25
  2. flatten_ndarray.py +0 -30
  3. line_plot.py +0 -44
  4. tempCodeRunnerFile.py +0 -4
  5. your_script.py +0 -47
data.py DELETED
@@ -1,25 +0,0 @@
1
- import gradio as gr
2
- import pandas as pd
3
- import numpy as np
4
- import random
5
- from gradio_datetimerange import DateTimeRange
6
- from datetime import datetime, timedelta
7
- now = datetime.now()
8
-
9
- df = pd.DataFrame({
10
- 'time': [now - timedelta(minutes=5*i) for i in range(25)],
11
- 'price': np.random.randint(100, 1000, 25),
12
- 'origin': [random.choice(["DFW", "DAL", "HOU"]) for _ in range(25)],
13
- 'destination': [random.choice(["JFK", "LGA", "EWR"]) for _ in range(25)],
14
- })
15
-
16
- if __name__ == "__main__":
17
- with gr.Blocks() as demo:
18
- daterange = DateTimeRange(["now - 24h", "now"])
19
- plot1 = gr.LinePlot(df, x="time", y="price")
20
- plot2 = gr.LinePlot(df, x="time", y="price", color="origin")
21
- daterange.bind([plot1, plot2])
22
-
23
- demo.launch(share=True)
24
- print(type(DateTimeRange))
25
- print(type(gr.LinePlot))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
flatten_ndarray.py DELETED
@@ -1,30 +0,0 @@
1
- import pandas as pd
2
- import numpy as np
3
-
4
- def flatten_ndarray_column(df, column_name):
5
- def flatten_ndarray(ndarray):
6
- if isinstance(ndarray, np.ndarray) and ndarray.dtype == 'O':
7
- return np.concatenate([flatten_ndarray(subarray) for subarray in ndarray])
8
- elif isinstance(ndarray, np.ndarray) and ndarray.ndim == 1:
9
- return np.expand_dims(ndarray, axis=0)
10
- return ndarray
11
-
12
- flattened_data = df[column_name].apply(flatten_ndarray)
13
- max_length = max(flattened_data.apply(len))
14
-
15
- for i in range(max_length):
16
- df[f'{column_name}_{i}'] = flattened_data.apply(lambda x: x[i] if i < len(x) else np.nan)
17
-
18
- return df
19
-
20
- # 示例用法
21
- if __name__ == "__main__":
22
- # 创建示例 DataFrame
23
- data = {
24
- 'target': [np.array([np.array([1, 2]), np.array([3, 4])]), np.array([5, 6, 7])]
25
- }
26
- df = pd.DataFrame(data)
27
-
28
- # 拆分 target 列中的嵌套 ndarray
29
- df = flatten_ndarray_column(df, 'target')
30
- print(df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
line_plot.py DELETED
@@ -1,44 +0,0 @@
1
- import pandas as pd
2
- from fastapi import FastAPI
3
- import plotly.graph_objects as go
4
- import gradio as gr
5
- import uvicorn
6
-
7
- def create_plot(df):
8
- fig = go.Figure()
9
- for column in df.columns[1:]:
10
- fig.add_trace(go.Scatter(x=df[df.columns[0]], y=df[column], mode='lines', name=column))
11
-
12
- # 配置图例
13
- fig.update_layout(
14
- legend=dict(
15
- title="Variables",
16
- orientation="h",
17
- yanchor="bottom",
18
- y=1.02,
19
- xanchor="right",
20
- x=1
21
- ),
22
- xaxis_title='Time',
23
- yaxis_title='Values'
24
- )
25
- return fig
26
-
27
- # 创建Gradio界面
28
- demo = gr.Blocks()
29
- with demo:
30
- # 示例数据
31
- data = {
32
- 'time': pd.date_range(start='2023-01-01', periods=6, freq='D'),
33
- 'y1': [0, 1, 4, 9, 16, 25],
34
- 'y2': [0, 1, 2, 3, 4, 5]
35
- }
36
- df = pd.DataFrame(data)
37
- plot = create_plot(df)
38
- gr.Plot(plot)
39
-
40
- # 运行Gradio界面
41
- if __name__ == "__main__":
42
- app = FastAPI()
43
- app = gr.mount_gradio_app(app, demo, path="/")
44
- uvicorn.run(app, host="127.0.0.1", port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tempCodeRunnerFile.py DELETED
@@ -1,4 +0,0 @@
1
- if __name__ == "__main__":
2
- # app = FastAPI()
3
- # app = gr.mount_gradio_app(app, demo, path="/")
4
- # uvicorn.run(app, host="127.0.0.1", port=7860)
 
 
 
 
 
your_script.py DELETED
@@ -1,47 +0,0 @@
1
- import altair as alt
2
- from fastapi import FastAPI
3
- import gradio as gr
4
- import numpy as np
5
- import pandas as pd
6
- import uvicorn
7
- from vega_datasets import data
8
-
9
-
10
- def plot(v, a):
11
- g = 9.81
12
- theta = a / 180 * 3.14
13
- tmax = ((2 * v) * np.sin(theta)) / g
14
- timemat = tmax * np.linspace(0, 1, 40)
15
-
16
- x = (v * timemat) * np.cos(theta)
17
- y = ((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat**2))
18
- df = pd.DataFrame({"x": x, "y": y})
19
- return df
20
-
21
- demo = gr.Blocks()
22
-
23
- with demo:
24
- gr.Markdown(
25
- r"Let's do some kinematics! Choose the speed and angle to see the trajectory. Remember that the range $R = v_0^2 \cdot \frac{\sin(2\theta)}{g}$"
26
- )
27
-
28
- with gr.Row():
29
- speed = gr.Slider(1, 30, 25, label="Speed")
30
- angle = gr.Slider(0, 90, 45, label="Angle")
31
- output = gr.LinePlot(
32
- x="x",
33
- y="y",
34
- overlay_point=True,
35
- tooltip=["x", "y"],
36
- x_lim=[0, 100],
37
- y_lim=[0, 60],
38
- width=350,
39
- height=300,
40
- )
41
- btn = gr.Button(value="Run")
42
- btn.click(plot, [speed, angle], output)
43
-
44
- if __name__ == "__main__":
45
- app = FastAPI()
46
- app = gr.mount_gradio_app(app, demo, path="/")
47
- uvicorn.run(app, host="127.0.0.1", port=7860)