Spaces:
Sleeping
Sleeping
Commit
·
4cdc4e2
1
Parent(s):
51b48a8
updated gradio to call the functions directly
Browse files
app.py
CHANGED
@@ -1,54 +1,50 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
|
|
3 |
import pandas as pd
|
4 |
-
import networkx as nx
|
5 |
import matplotlib.pyplot as plt
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
def
|
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 |
-
# Return results
|
36 |
-
return (df_results.head().to_dict("records"), csv_path, "graph.png", explanation)
|
37 |
|
38 |
iface = gr.Interface(
|
39 |
-
fn=
|
40 |
-
inputs=gr.File(label="Upload CSV"
|
41 |
outputs=[
|
42 |
-
gr.
|
43 |
gr.File(label="Download CSV"),
|
44 |
-
gr.Image(label="
|
45 |
-
gr.Textbox(label="
|
46 |
],
|
47 |
title="DeepFunding Oracle",
|
48 |
-
description=
|
49 |
-
|
50 |
-
"and visualize the dependency graph with explanations."
|
51 |
-
)
|
52 |
)
|
53 |
|
54 |
if __name__ == "__main__":
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
from Oracle.deepfundingoracle import prepare_dataset, train_predict_weight, create_submission_csv
|
4 |
import pandas as pd
|
|
|
5 |
import matplotlib.pyplot as plt
|
6 |
+
import time
|
7 |
+
import io
|
8 |
|
9 |
+
def analyze_file(file, progress=gr.Progress(track_tqdm=True)):
|
10 |
+
start_time = time.time()
|
11 |
+
progress(0, desc="Preparing dataset...")
|
12 |
+
df = prepare_dataset(file.name)
|
13 |
+
progress(0.3, desc="Predicting weights...")
|
14 |
+
df = train_predict_weight(df)
|
15 |
+
progress(0.6, desc="Saving results to CSV...")
|
16 |
+
csv_path = create_submission_csv(df, "submission.csv")
|
17 |
+
progress(0.8, desc="Generating graph...")
|
18 |
+
# Example: plot histogram of a column if exists
|
19 |
+
fig, ax = plt.subplots()
|
20 |
+
if 'final_weight' in df.columns:
|
21 |
+
df['final_weight'].hist(ax=ax)
|
22 |
+
ax.set_title('Distribution of Final Weights')
|
23 |
+
ax.set_xlabel('Final Weight')
|
24 |
+
ax.set_ylabel('Count')
|
25 |
+
else:
|
26 |
+
ax.text(0.5, 0.5, 'No final_weight column to plot', ha='center')
|
27 |
+
buf = io.BytesIO()
|
28 |
+
plt.savefig(buf, format='png')
|
29 |
+
buf.seek(0)
|
30 |
+
plt.close(fig)
|
31 |
+
progress(1, desc="Done!")
|
32 |
+
elapsed = time.time() - start_time
|
33 |
+
preview = df.head().to_csv(index=False)
|
34 |
+
return preview, csv_path, buf, f"Analysis completed in {elapsed:.2f} seconds."
|
|
|
|
|
35 |
|
36 |
iface = gr.Interface(
|
37 |
+
fn=analyze_file,
|
38 |
+
inputs=gr.File(label="Upload CSV"),
|
39 |
outputs=[
|
40 |
+
gr.Textbox(label="Preview of Results"),
|
41 |
gr.File(label="Download CSV"),
|
42 |
+
gr.Image(label="Analysis Graph"),
|
43 |
+
gr.Textbox(label="Status/Timing Info")
|
44 |
],
|
45 |
title="DeepFunding Oracle",
|
46 |
+
description="Upload a CSV of repo-parent relationships; see analysis progress, get a graph, and download results as CSV.",
|
47 |
+
allow_flagging="never"
|
|
|
|
|
48 |
)
|
49 |
|
50 |
if __name__ == "__main__":
|