KawshikManikantan commited on
Commit
6084ae2
·
1 Parent(s): be327e5

changed to tempfile

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -7,6 +7,7 @@ from spacy.tokens import Doc, Span
7
  from spacy import displacy
8
  import matplotlib.pyplot as plt
9
  from matplotlib.colors import to_hex
 
10
 
11
  from inference.model_inference import Inference
12
  from configs import *
@@ -65,14 +66,26 @@ def coref_visualizer(doc_name, text, model_type):
65
 
66
  ## Create a hash based on time and doc_name
67
  time_hash = hash(str(time.time()) + doc_name)
68
- html_file = f"temp/gradio_outputs/output_{time_hash}.html"
69
- json_file = f"temp/gradio_outputs/output_{time_hash}.json"
70
 
71
- with open(html_file, "w") as f:
72
- f.write(html)
 
 
73
 
74
- with open(json_file, "w") as f:
75
- json.dump(coref_output, f)
 
 
 
 
 
 
 
 
 
 
76
 
77
  return (
78
  html_file,
 
7
  from spacy import displacy
8
  import matplotlib.pyplot as plt
9
  from matplotlib.colors import to_hex
10
+ import tempfile
11
 
12
  from inference.model_inference import Inference
13
  from configs import *
 
66
 
67
  ## Create a hash based on time and doc_name
68
  time_hash = hash(str(time.time()) + doc_name)
69
+ # html_file = f"temp/gradio_outputs/output_{time_hash}.html"
70
+ # json_file = f"temp/gradio_outputs/output_{time_hash}.json"
71
 
72
+ # Create a temporary HTML file
73
+ with tempfile.NamedTemporaryFile(suffix=".html", delete=False) as tmp_html_file:
74
+ html_file = tmp_html_file.name
75
+ tmp_html_file.write(html.encode("utf-8"))
76
 
77
+ with tempfile.NamedTemporaryFile(suffix=".json", delete=False) as tmp_json_file:
78
+ json_file = tmp_json_file.name
79
+ tmp_json_file.write(json.dumps(coref_output).encode("utf-8"))
80
+
81
+ # with open(html_file, "w") as f:
82
+ # f.write(html)
83
+
84
+ # with open(json_file, "w") as f:
85
+ # json.dump(coref_output, f)
86
+
87
+ print("HTML file:", html_file)
88
+ print("JSON file:", json_file)
89
 
90
  return (
91
  html_file,