grobid-evaluation / service.py
lfoppiano's picture
Update service.py
0da5c1b verified
raw
history blame
1.84 kB
import http.server
import socketserver
import subprocess
import threading
PORT = 8080
command_executed = False
command_output = []
def run_command():
global command_output
commands = [
# ['git clone --depth 1 https://huggingface.co/datasets/sciencialab/grobid-evaluation evaluation'],
['./gradlew', 'jatsEval', '-Pp2t=/opt/grobid/evaluation/PMC_sample_1943', '-Prun=1', '-PfileRatio=1'],
['./gradlew', 'jatsEval', '-Pp2t=/opt/grobid/evaluation/PLOS_1000', '-Prun=1', '-PfileRatio=1'],
['./gradlew', 'jatsEval', '-Pp2t=/opt/grobid/evaluation/biorxiv-10k-test-2000', '-Prun=1', '-PfileRatio=1'],
['./gradlew', 'jatsEval', '-Pp2t=/opt/grobid/evaluation/eLife_984', '-Prun=1', '-PfileRatio=1']
]
for command in commands:
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
for line in process.stdout:
command_output.append(line)
for line in process.stderr:
command_output.append(line)
process.stdout.close()
process.stderr.close()
process.wait()
class Handler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
global command_executed, command_output
if not command_executed:
command_executed = True
threading.Thread(target=run_command).start()
response = "Command is being executed."
else:
response = "Command output:\n" + "".join(command_output)
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
self.wfile.write(response.encode())
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print(f"Serving on port {PORT}")
httpd.serve_forever()