Spaces:
Build error
Build error
Commit ·
5d0030d
1
Parent(s): b05a860
update
Browse filesFiles changed (2)
- app.py+3-23
- templates/experiment.html+2-6
5 unmodified lines6789101112122 unmodified lines1351361371381391401411421431441451461471481491501511521531541551561571581594 unmodified lines1641651661671681691701711721731741753 unmodified lines1791801811821831841851 unmodified line1871881891901911921935 unmodified linesimport loggingfrom datetime import datetimefrom huggingface_hub import login, HfApi, hf_hub_downloadfrom bs4 import BeautifulSoup# Set up logginglogging.basicConfig(level=logging.INFO,122 unmodified linesreturn "An error occurred", 500return render_template('index.html')from bs4 import BeautifulSoupimport redef remove_prediction_from_html(html_content):soup = BeautifulSoup(html_content, 'html.parser')# Remove the Prediction lineprediction_h3 = soup.find('h3', string=re.compile(r'Prediction:'))if prediction_h3:prediction_h3.decompose()return str(soup)@app.route('/experiment/<username>', methods=['GET', 'POST'])def experiment(username):try:session_data = load_session_data(username)if not session_data:logger.error(f"Failed to load session data for user: {username}")return redirect(url_for('index'))selected_samples = session_data['selected_samples']4 unmodified linesreturn redirect(url_for('completed', username=username))sample = selected_samples[current_index]visualization_path = f"{VISUALIZATION_DIRS[method]}/{sample['category']}/{sample['file']}"# Modify the HTML content for all methodswith open(visualization_path, 'r', encoding='utf-8') as file:html_content = file.read()modified_html = remove_prediction_from_html(html_content)statement = """Based on the explanation provided, what do you think the AI model will predict?3 unmodified linesreturn render_template('experiment.html',sample_id=current_index,statement=statement,visualization_content=modified_html,username=username,method=method)except Exception as e:1 unmodified linereturn "An error occurred", 500@app.route('/feedback', methods=['POST'])def feedback():try:5 unmodified lines67891011122 unmodified lines1341351361371381391401411421431444 unmodified lines1491501511521531541551563 unmodified lines1601611621631641651661 unmodified line1681691701711721735 unmodified linesimport loggingfrom datetime import datetimefrom huggingface_hub import login, HfApi, hf_hub_download# Set up logginglogging.basicConfig(level=logging.INFO,122 unmodified linesreturn "An error occurred", 500return render_template('index.html')@app.route('/experiment/<username>', methods=['GET', 'POST'])def experiment(username):try:session_data = load_session_data(username)if not session_data:return redirect(url_for('index'))selected_samples = session_data['selected_samples']4 unmodified linesreturn redirect(url_for('completed', username=username))sample = selected_samples[current_index]visualization_dir = VISUALIZATION_DIRS[method]visualization_path = f"{visualization_dir}/{sample['category']}/{sample['file']}"statement = """Based on the explanation provided, what do you think the AI model will predict?3 unmodified linesreturn render_template('experiment.html',sample_id=current_index,statement=statement,visualization=url_for('send_visualization', filename=visualization_path),username=username,method=method)except Exception as e:1 unmodified linereturn "An error occurred", 500@app.route('/feedback', methods=['POST'])def feedback():try:
34 unmodified lines3536373839404137 unmodified lines798081828384858687888934 unmodified linesdisplay: flex;justify-content: center;align-items: center;overflow: auto;}iframe {width: 100%;37 unmodified lines<p><strong>Task description:</strong> {{ statement }}</p></div><div class="visualization-container">{% if visualization_content %}<div>{{ visualization_content | safe }}</div>{% else %}<p>No visualization available.</p>{% endif %}</div><div class="buttons"><form action="{{ url_for('feedback') }}" method="post">34 unmodified lines3536373839404137 unmodified lines7980818283848534 unmodified linesdisplay: flex;justify-content: center;align-items: center;overflow: hidden;}iframe {width: 100%;37 unmodified lines<p><strong>Task description:</strong> {{ statement }}</p></div><div class="visualization-container"><iframe src="{{ visualization }}"></iframe></div><div class="buttons"><form action="{{ url_for('feedback') }}" method="post">
app.py+3-23
templates/experiment.html+2-6