File size: 1,322 Bytes
b2272b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import gradio as gr
import git
import tempfile
import shutil
import subprocess
import os

cwd = os.getcwd()
gcounter = 1000

def generate_git(OldVersion, NewVersion, tmp_dir_name):
  new_repo = git.Repo.init(tmp_dir_name)
  with new_repo.config_writer() as git_config:
    git_config.set_value('user', 'email', '[email protected]')
    git_config.set_value('user', 'name', 'git Latex Diff')

  shutil.unpack_archive(OldVersion.name, tmp_dir_name)

  new_repo.index.add('*')
  new_repo.index.commit('Initial commit.')

  shutil.unpack_archive(NewVersion.name, tmp_dir_name)

  new_repo.index.add('*')
  new_repo.index.commit('Changes')

def generate_diff(tmp_dir_name):
  subprocess.check_call([f'{cwd}/git-latexdiff',  'HEAD~1', '--cleanup', 'keeppdf', '-o', 'mydiff.pdf'], cwd=tmp_dir_name)

def gen_all(OldVersion, NewVersion):
  global gcounter
  gcounter+=1

  dirpath = tempfile.mkdtemp()
  fake_git_name = 'something'
  generate_git(OldVersion, NewVersion, dirpath)
  generate_diff(dirpath)
  shutil.move(f'{dirpath}/mydiff.pdf', f'{cwd}/results/{gcounter}.pdf')
  shutil.rmtree(dirpath)

  return f'{cwd}/results/{gcounter}.pdf'

os.makedirs('results', exist_ok=True)

iface = gr.Interface(gen_all, ["file", "file"], "file", allow_screenshot=False, allow_flagging=False)
iface.launch(enable_queue=True)