Spaces:
Build error
Build error
Commit ·
f79d6c4
1
Parent(s): c9ab476
+ download of csv
Browse filesFiles changed (3)
12234env*.env*.env*review.csv*.csv8 unmodified lines910111213141540 unmodified lines565758585960616263646566672 unmodified lines707172677374757677787980817182838485868788899030 unmodified lines12112212310812412512612712812913013113213313413513613713813914014114214375 unmodified lines2192202212222232242252262271932282292302312322332342002352362372388 unmodified linesimport aiohttpfrom langfuse.langchain import CallbackHandlerfrom langchain_core.messages import HumanMessageimport tempfile
# Initialize Langfuse CallbackHandler for LangGraph/Langchain (tracing)langfuse_handler = CallbackHandler()40 unmodified lines print(f"User logged in: {username}") else: print("User not logged in.") return "Please Login to Hugging Face with the button.", None, gr.update(interactive=False), gr.update(value=0, visible=False) return ( "Please Login to Hugging Face with the button.", None, gr.update(interactive=False), # Disable submit button gr.update(value=None, visible=False), # Hide download button ) api_url = DEFAULT_API_URL questions_url = f"{api_url}/questions" try:2 unmodified lines questions_data = response.json() if not questions_data: print("Fetched questions list is empty.") return "Fetched questions list is empty or invalid format.", None, gr.update(interactive=False), gr.update(value=0, visible=False) return ( "Fetched questions list is empty or invalid format.", None, gr.update(interactive=False), gr.update(value=None, visible=False), ) print(f"Fetched {len(questions_data)} questions.") except Exception as e: print(f"Error fetching questions: {e}") return f"Error fetching questions: {e}", None, gr.update(interactive=False), gr.update(value=0, visible=False) return ( f"Error fetching questions: {e}", None, gr.update(interactive=False), gr.update(value=None, visible=False), ) agent = BasicAgent() results_log = [] answers_payload = []30 unmodified lines cached_results_log = results_log progress(100, desc="Done.") results_df = pd.DataFrame(results_log) return "Answer generation complete. Review and submit.", results_df, gr.update(interactive=True), gr.update(value=100, visible=True)
# Save answers to a temporary CSV so user can download try: with tempfile.NamedTemporaryFile(delete=False, suffix=".csv", mode="w", newline="", encoding="utf-8") as tmp_csv: results_df.to_csv(tmp_csv.name, index=False) csv_path = tmp_csv.name print(f"CSV saved to {csv_path}") except Exception as e: print(f"Failed to write CSV: {e}") csv_path = None
return ( "Answer generation complete. Review and submit.", results_df, gr.update(interactive=True), # Enable submit button gr.update(value=csv_path, visible=bool(csv_path)), # Show download button if csv written )
def submit_answers(profile: gr.OAuthProfile | None): """75 unmodified lines status_output = gr.Textbox(label="Status / Submission Result", lines=5, interactive=False) results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
# Download button appears after answers are generated download_button = gr.DownloadButton(label="Download Answers CSV", visible=False)
generate_button.click( fn=generate_answers, inputs=[], outputs=[status_output, results_table, submit_button], outputs=[status_output, results_table, submit_button, download_button], api_name="generate_answers" ) submit_button.click( fn=submit_answers, inputs=[], outputs=[status_output, results_table], api_name="submit_answers" api_name="submit_answers", )
if __name__ == "__main__":.gitignore+3-1
__pycache__/langraph_agent.cpython-313.pyc
app.py+41-6