Seetha commited on
Commit
767adb0
·
1 Parent(s): 7a3ffbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -108
app.py CHANGED
@@ -65,11 +65,6 @@ import urllib.request
65
  import gradio as gr
66
  from gradio import inputs, outputs
67
 
68
- DATASET_REPO_URL = "https://huggingface.co/datasets/Seetha/Visualization/level2.json"
69
- DATASET_REPO_ID = "Seetha/Visualization/level2.json"
70
- DATA_FILENAME = "level2.json"
71
- DATA_FILE = os.path.join("level2", DATA_FILENAME)
72
- HF_TOKEN = os.environ.get("HF_TOKEN")
73
 
74
  def main():
75
 
@@ -480,44 +475,6 @@ def main():
480
  fi.write(dat)
481
  fi.truncate()
482
 
483
- # dataset = load_dataset("Seetha/Visualization")
484
- # st.write(dataset)
485
- # with open(DATA_FILE,'w') as f:
486
- # json.dump(json_data, f)
487
- #repo.push_to_hub()
488
- # Write JSON to file
489
- #with open(DATA_FILE, 'w') as f: #w+
490
- # with urllib.request.urlopen('https://huggingface.co/datasets/Seetha/visual_files/raw/main/level2.json') as response:
491
- # data = response.read()
492
-
493
- # # with open('level2.json','w') as f:
494
- # # st.write(f.read())
495
- # # #st.write(f.write(json.dump(json_data)))
496
- # # #f.write(json.dump(json_data))
497
- # # json.dump(json_data, f)
498
- # with open('level2.json', "w+") as f:
499
- # # data = f.read()
500
- # # #st.write(data)
501
- # # f.seek(0)
502
- # st.write(str(json_data))
503
- # json.dump(json_data, f)
504
-
505
- # def store_message():
506
- # with open(DATA_FILE, "w") as f:
507
- # json.dump(json_data, f)
508
- # commit_url = repo.push_to_hub()
509
- # st.write(commit_url)
510
-
511
- # #return generate_html()
512
- #with gr.Blocks() as demo:
513
- # iface = gr.Interface(
514
- # save_feedback()
515
- # )
516
-
517
- # iface.launch()
518
-
519
- #f.truncate()
520
-
521
  df_final1.to_csv('predictions.csv')
522
  csv_file = "predictions.csv"
523
  json_file = "detailedResults.json"
@@ -542,71 +499,6 @@ def main():
542
  #data = json.load(fi)
543
  fi.write(json_data)
544
 
545
- # # overriding/appending to the gradio template
546
- # SCRIPT = """
547
- # <script>
548
- # if (!window.hasBeenRun) {
549
- # window.hasBeenRun = true;
550
- # console.log("should only happen once");
551
- # document.querySelector("button.submit").click();
552
- # }
553
- # </script>
554
- # """
555
- # with open(os.path.join(gr.networking.STATIC_TEMPLATE_LIB, "frontend", "index.html"), "a") as f:
556
- # f.write(SCRIPT)
557
-
558
- try:
559
- hf_hub_download(
560
- repo_id=DATASET_REPO_ID,
561
- filename=DATA_FILENAME,
562
- cache_dir=DATA_DIRNAME,
563
- force_filename=DATA_FILENAME
564
- )
565
- except:
566
- st.write("file not found")
567
-
568
- repo = Repository(
569
- local_dir="level2", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
570
- )
571
-
572
- # def generate_html() -> str:
573
- # with open(DATA_FILE) as csvfile:
574
- # reader = json.dumps(json_data)
575
- # rows = []
576
- # for row in reader:
577
- # rows.append(row)
578
- # rows.reverse()
579
- # if len(rows) == 0:
580
- # return "no messages yet"
581
- # else:
582
- # html = "<div class='chatbot'>"
583
- # for row in rows:
584
- # html += "<div>"
585
- # html += f"<span>{row['name']}</span>"
586
- # html += f"<span class='message'>{row['message']}</span>"
587
- # html += "</div>"
588
- # html += "</div>"
589
- # return html
590
-
591
- def store_message():
592
- if name and message:
593
- with open(DATA_FILE, "a") as csvfile:
594
- writer = json.dumps(json_data)
595
- commit_url = repo.push_to_hub()
596
- # return generate_html()
597
-
598
- iface = gr.Interface(
599
- store_message,
600
- "html",
601
- css="""
602
- .message {background-color:cornflowerblue;color:white; padding:4px;margin:4px;border-radius:4px; }
603
- """,
604
- title="Reading/writing to a HuggingFace dataset repo from Spaces",
605
- description=f"This is a demo of how to do simple *shared data persistence* in a Gradio Space, backed by a dataset repo.",
606
- article=f"The dataset repo is [{DATASET_REPO_URL}]({DATASET_REPO_URL})",
607
- )
608
-
609
- iface.launch()
610
  def convert_df(df):
611
 
612
  #IMPORTANT: Cache the conversion to prevent computation on every rerun
 
65
  import gradio as gr
66
  from gradio import inputs, outputs
67
 
 
 
 
 
 
68
 
69
  def main():
70
 
 
475
  fi.write(dat)
476
  fi.truncate()
477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  df_final1.to_csv('predictions.csv')
479
  csv_file = "predictions.csv"
480
  json_file = "detailedResults.json"
 
499
  #data = json.load(fi)
500
  fi.write(json_data)
501
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502
  def convert_df(df):
503
 
504
  #IMPORTANT: Cache the conversion to prevent computation on every rerun