File size: 1,863 Bytes
b2272b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71c387f
d4df8ff
71c387f
 
 
 
 
 
 
 
d4df8ff
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
48
49
50
51
52
53
54
55
56
57
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)

title = "Latex Diff"
description = "This Space automatically generates LatexDiff for two different versions of your latex project. Upload two zip files from different stages of your latex project, and it will generate a latex diff."
article = "<p style='text-align: center'><a href='https://gitlab.com/git-latexdiff/git-latexdiff' target='_blank'>Git LatexDiff GitLab Repo</a></p>"


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