yalrashed commited on
Commit
92074f4
·
verified ·
1 Parent(s): 9879995

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -17,15 +17,26 @@ class ConsoleOutput:
17
  def get_output(self):
18
  return "\n".join(self.messages)
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  def process_screenplay(pdf_file, progress=gr.Progress()):
21
  if pdf_file is None:
22
  raise gr.Error("Please upload a PDF file")
23
 
24
  console = ConsoleOutput()
25
- logging.basicConfig(level=logging.DEBUG)
26
- logger = logging.getLogger()
27
- logger.handlers = []
28
- logger.addHandler(GradioHandler())
29
 
30
  try:
31
  processor = GeminiProcessor()
@@ -50,10 +61,7 @@ def process_screenplay(pdf_file, progress=gr.Progress()):
50
 
51
  def generate_coverage(progress=gr.Progress()):
52
  console = ConsoleOutput()
53
- logging.basicConfig(level=logging.DEBUG)
54
- logger = logging.getLogger()
55
- logger.handlers = []
56
- logger.addHandler(GradioHandler())
57
 
58
  try:
59
  coverage_gen = CoverageGenerator()
@@ -77,10 +85,7 @@ def generate_coverage(progress=gr.Progress()):
77
 
78
  def analyze_screenplay(progress=gr.Progress()):
79
  console = ConsoleOutput()
80
- logging.basicConfig(level=logging.DEBUG)
81
- logger = logging.getLogger()
82
- logger.handlers = []
83
- logger.addHandler(GradioHandler())
84
 
85
  try:
86
  analyzer = CreativeAnalyzer()
 
17
  def get_output(self):
18
  return "\n".join(self.messages)
19
 
20
+ class GradioHandler(logging.Handler):
21
+ def emit(self, record):
22
+ msg = self.format(record)
23
+ self.console.write(msg)
24
+
25
+ def setup_logging(console_output):
26
+ logging.basicConfig(level=logging.DEBUG)
27
+ logger = logging.getLogger()
28
+ logger.handlers = []
29
+ handler = GradioHandler()
30
+ handler.console = console_output
31
+ logger.addHandler(handler)
32
+ return logger
33
+
34
  def process_screenplay(pdf_file, progress=gr.Progress()):
35
  if pdf_file is None:
36
  raise gr.Error("Please upload a PDF file")
37
 
38
  console = ConsoleOutput()
39
+ logger = setup_logging(console)
 
 
 
40
 
41
  try:
42
  processor = GeminiProcessor()
 
61
 
62
  def generate_coverage(progress=gr.Progress()):
63
  console = ConsoleOutput()
64
+ logger = setup_logging(console)
 
 
 
65
 
66
  try:
67
  coverage_gen = CoverageGenerator()
 
85
 
86
  def analyze_screenplay(progress=gr.Progress()):
87
  console = ConsoleOutput()
88
+ logger = setup_logging(console)
 
 
 
89
 
90
  try:
91
  analyzer = CreativeAnalyzer()