Spaces:
Sleeping
Sleeping
Commit
Β·
99de051
1
Parent(s):
bf9b592
Oracle
Browse files
app.py
CHANGED
@@ -10,13 +10,11 @@ from PIL import Image
|
|
10 |
import logging
|
11 |
|
12 |
# Import the functions from deepfundingoracle
|
13 |
-
from Oracle.deepfundingoracle import prepare_dataset, train_predict_weight, create_submission_csv,
|
14 |
-
normalize_and_clip_weights
|
15 |
|
16 |
# Configure logging
|
17 |
logging.basicConfig(level=logging.INFO)
|
18 |
|
19 |
-
|
20 |
def analyze_file(file, progress=gr.Progress(track_tqdm=True)):
|
21 |
"""
|
22 |
Analyzes the uploaded file and generates results.
|
@@ -47,8 +45,7 @@ def analyze_file(file, progress=gr.Progress(track_tqdm=True)):
|
|
47 |
# Feature distribution plot
|
48 |
dist_fig = plt.figure(figsize=(15, 10))
|
49 |
numeric_cols = df.select_dtypes(include=[np.number]).columns
|
50 |
-
plot_cols = [col for col in numeric_cols if
|
51 |
-
col in ['stars', 'forks', 'watchers', 'contributors', 'pulls', 'final_weight']]
|
52 |
|
53 |
if plot_cols:
|
54 |
df[plot_cols].hist(bins=20, figsize=(15, 10), color="skyblue", edgecolor="black")
|
@@ -82,10 +79,9 @@ def analyze_file(file, progress=gr.Progress(track_tqdm=True)):
|
|
82 |
summary_df = df[['repo', 'parent', 'final_weight']].head(10)
|
83 |
preview = f"Top 10 Results:\n{summary_df.to_string(index=False)}\n\nTotal repositories analyzed: {len(df)}"
|
84 |
|
85 |
-
# Return the path to the generated file for automatic download
|
86 |
return (
|
87 |
preview,
|
88 |
-
output_filename,
|
89 |
dist_img,
|
90 |
corr_img,
|
91 |
f"β
Analysis completed successfully in {elapsed:.2f} seconds.\nπ₯ Results file ready for download!"
|
@@ -100,7 +96,6 @@ def analyze_file(file, progress=gr.Progress(track_tqdm=True)):
|
|
100 |
empty_img = Image.new('RGB', (800, 600), color='white')
|
101 |
return error_msg, None, empty_img, empty_img, error_msg
|
102 |
|
103 |
-
|
104 |
# Custom CSS for better styling
|
105 |
custom_css = """
|
106 |
.download-button {
|
@@ -115,7 +110,7 @@ custom_css = """
|
|
115 |
}
|
116 |
"""
|
117 |
|
118 |
-
# Create Gradio interface
|
119 |
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as iface:
|
120 |
gr.Markdown("""
|
121 |
# π DeepFunding Oracle
|
@@ -166,37 +161,11 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as iface:
|
|
166 |
with gr.Column():
|
167 |
corr_plot = gr.Image(label="Feature Correlation Matrix")
|
168 |
|
169 |
-
#
|
170 |
-
download_js = """
|
171 |
-
() => {
|
172 |
-
setTimeout(() => {
|
173 |
-
const downloadButton = document.querySelector('.download-button a');
|
174 |
-
if (downloadButton) {
|
175 |
-
downloadButton.click();
|
176 |
-
}
|
177 |
-
}, 500);
|
178 |
-
}
|
179 |
-
"""
|
180 |
-
|
181 |
-
# Set up the event handler
|
182 |
analyze_btn.click(
|
183 |
fn=analyze_file,
|
184 |
inputs=[file_input],
|
185 |
outputs=[preview_output, download_output, dist_plot, corr_plot, status_output]
|
186 |
-
).then(
|
187 |
-
fn=None,
|
188 |
-
inputs=None,
|
189 |
-
outputs=None,
|
190 |
-
_js=download_js # This triggers automatic download
|
191 |
-
)
|
192 |
-
|
193 |
-
# Add example usage
|
194 |
-
gr.Examples(
|
195 |
-
examples=[["example_dependencies.csv"]], # Add your example file here if you have one
|
196 |
-
inputs=file_input,
|
197 |
-
outputs=[preview_output, download_output, dist_plot, corr_plot, status_output],
|
198 |
-
fn=analyze_file,
|
199 |
-
cache_examples=False,
|
200 |
)
|
201 |
|
202 |
if __name__ == "__main__":
|
|
|
10 |
import logging
|
11 |
|
12 |
# Import the functions from deepfundingoracle
|
13 |
+
from Oracle.deepfundingoracle import prepare_dataset, train_predict_weight, create_submission_csv, normalize_and_clip_weights
|
|
|
14 |
|
15 |
# Configure logging
|
16 |
logging.basicConfig(level=logging.INFO)
|
17 |
|
|
|
18 |
def analyze_file(file, progress=gr.Progress(track_tqdm=True)):
|
19 |
"""
|
20 |
Analyzes the uploaded file and generates results.
|
|
|
45 |
# Feature distribution plot
|
46 |
dist_fig = plt.figure(figsize=(15, 10))
|
47 |
numeric_cols = df.select_dtypes(include=[np.number]).columns
|
48 |
+
plot_cols = [col for col in numeric_cols if col in ['stars', 'forks', 'watchers', 'contributors', 'pulls', 'final_weight']]
|
|
|
49 |
|
50 |
if plot_cols:
|
51 |
df[plot_cols].hist(bins=20, figsize=(15, 10), color="skyblue", edgecolor="black")
|
|
|
79 |
summary_df = df[['repo', 'parent', 'final_weight']].head(10)
|
80 |
preview = f"Top 10 Results:\n{summary_df.to_string(index=False)}\n\nTotal repositories analyzed: {len(df)}"
|
81 |
|
|
|
82 |
return (
|
83 |
preview,
|
84 |
+
output_filename,
|
85 |
dist_img,
|
86 |
corr_img,
|
87 |
f"β
Analysis completed successfully in {elapsed:.2f} seconds.\nπ₯ Results file ready for download!"
|
|
|
96 |
empty_img = Image.new('RGB', (800, 600), color='white')
|
97 |
return error_msg, None, empty_img, empty_img, error_msg
|
98 |
|
|
|
99 |
# Custom CSS for better styling
|
100 |
custom_css = """
|
101 |
.download-button {
|
|
|
110 |
}
|
111 |
"""
|
112 |
|
113 |
+
# Create Gradio interface
|
114 |
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as iface:
|
115 |
gr.Markdown("""
|
116 |
# π DeepFunding Oracle
|
|
|
161 |
with gr.Column():
|
162 |
corr_plot = gr.Image(label="Feature Correlation Matrix")
|
163 |
|
164 |
+
# Set up the event handler (without _js parameter)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
analyze_btn.click(
|
166 |
fn=analyze_file,
|
167 |
inputs=[file_input],
|
168 |
outputs=[preview_output, download_output, dist_plot, corr_plot, status_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
)
|
170 |
|
171 |
if __name__ == "__main__":
|