Spaces:
Sleeping
Sleeping
Commit ·
99de051
1
Parent(s): bf9b592
Oracle
Browse files9 unmodified lines1011121314151617181920212224 unmodified lines474849505152535427 unmodified lines828384858687888990918 unmodified lines1001011021031041051068 unmodified lines11511611711811912012144 unmodified lines1661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012029 unmodified linesimport logging# Import the functions from deepfundingoraclefrom Oracle.deepfundingoracle import prepare_dataset, train_predict_weight, create_submission_csv, \normalize_and_clip_weights# Configure logginglogging.basicConfig(level=logging.INFO)def analyze_file(file, progress=gr.Progress(track_tqdm=True)):"""Analyzes the uploaded file and generates results.24 unmodified lines# Feature distribution plotdist_fig = plt.figure(figsize=(15, 10))numeric_cols = df.select_dtypes(include=[np.number]).columnsplot_cols = [col for col in numeric_cols ifcol in ['stars', 'forks', 'watchers', 'contributors', 'pulls', 'final_weight']]if plot_cols:df[plot_cols].hist(bins=20, figsize=(15, 10), color="skyblue", edgecolor="black")27 unmodified linessummary_df = df[['repo', 'parent', 'final_weight']].head(10)preview = f"Top 10 Results:\n{summary_df.to_string(index=False)}\n\nTotal repositories analyzed: {len(df)}"# Return the path to the generated file for automatic downloadreturn (preview,output_filename, # This will trigger automatic downloaddist_img,corr_img,f"✅ Analysis completed successfully in {elapsed:.2f} seconds.\n📥 Results file ready for download!"8 unmodified linesempty_img = Image.new('RGB', (800, 600), color='white')return error_msg, None, empty_img, empty_img, error_msg# Custom CSS for better stylingcustom_css = """.download-button {8 unmodified lines}"""# Create Gradio interface with automatic downloadwith gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as iface:gr.Markdown("""# 🚀 DeepFunding Oracle44 unmodified lineswith gr.Column():corr_plot = gr.Image(label="Feature Correlation Matrix")# JavaScript for automatic downloaddownload_js = """() => {setTimeout(() => {const downloadButton = document.querySelector('.download-button a');if (downloadButton) {downloadButton.click();}}, 500);}"""# Set up the event handleranalyze_btn.click(fn=analyze_file,inputs=[file_input],outputs=[preview_output, download_output, dist_plot, corr_plot, status_output]).then(fn=None,inputs=None,outputs=None,_js=download_js # This triggers automatic download)# Add example usagegr.Examples(examples=[["example_dependencies.csv"]], # Add your example file here if you have oneinputs=file_input,outputs=[preview_output, download_output, dist_plot, corr_plot, status_output],fn=analyze_file,cache_examples=False,)if __name__ == "__main__":9 unmodified lines101112131415161718192024 unmodified lines4546474849505127 unmodified lines7980818283848586878 unmodified lines969798991001018 unmodified lines11011111211311411511644 unmodified lines1611621631641651661671681691701719 unmodified linesimport logging# Import the functions from deepfundingoraclefrom Oracle.deepfundingoracle import prepare_dataset, train_predict_weight, create_submission_csv, normalize_and_clip_weights# Configure logginglogging.basicConfig(level=logging.INFO)def analyze_file(file, progress=gr.Progress(track_tqdm=True)):"""Analyzes the uploaded file and generates results.24 unmodified lines# Feature distribution plotdist_fig = plt.figure(figsize=(15, 10))numeric_cols = df.select_dtypes(include=[np.number]).columnsplot_cols = [col for col in numeric_cols if col in ['stars', 'forks', 'watchers', 'contributors', 'pulls', 'final_weight']]if plot_cols:df[plot_cols].hist(bins=20, figsize=(15, 10), color="skyblue", edgecolor="black")27 unmodified linessummary_df = df[['repo', 'parent', 'final_weight']].head(10)preview = f"Top 10 Results:\n{summary_df.to_string(index=False)}\n\nTotal repositories analyzed: {len(df)}"return (preview,output_filename,dist_img,corr_img,f"✅ Analysis completed successfully in {elapsed:.2f} seconds.\n📥 Results file ready for download!"8 unmodified linesempty_img = Image.new('RGB', (800, 600), color='white')return error_msg, None, empty_img, empty_img, error_msg# Custom CSS for better stylingcustom_css = """.download-button {8 unmodified lines}"""# Create Gradio interfacewith gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as iface:gr.Markdown("""# 🚀 DeepFunding Oracle44 unmodified lineswith gr.Column():corr_plot = gr.Image(label="Feature Correlation Matrix")# Set up the event handler (without _js parameter)analyze_btn.click(fn=analyze_file,inputs=[file_input],outputs=[preview_output, download_output, dist_plot, corr_plot, status_output])if __name__ == "__main__":
app.py+5-36