File size: 1,420 Bytes
176b16b
 
2f37cf4
176b16b
2f37cf4
 
 
176b16b
 
2f37cf4
 
 
545426f
2f37cf4
 
 
 
 
 
 
 
 
 
 
 
 
 
cc7d2be
 
2f37cf4
 
 
cef866d
2f37cf4
176b16b
2f37cf4
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
from subprocess import run

import gradio as gr
from huggingface_hub import snapshot_download

from corporate_emission_reports.inference import extract_emissions

run(["sh", "install-llamacpp.sh"])
MODEL_PATH = snapshot_download("nopperl/emissions-extraction-lora-merged-GGUF")

def predict(input_method, document_file, document_url):
    document_path = document_file if input_method == "File" else document_url
    emissions = extract_emissions(document_path, MODEL_PATH, model_name="ggml-model-Q5_K_M.gguf")
    return emissions.model_dump_json()

with open("description.md", "r") as f:
    description = f.read().strip()

with open("article.md", "r") as f:
    article = f.read().strip()

interface = gr.Interface(
        predict,
        inputs=[gr.Radio(choices=["File", "URL"], value="File"), gr.File(type="filepath", file_types=[".pdf"], file_count="single", label="Report File"), gr.Textbox(label="Report URL")],
        outputs=gr.JSON(),
        description=description,
        examples = [
            ["URL", None, "https://www.deutsche-boerse.com/resource/blob/3373890/1cdeb942b1a02ce3495e25240dfdfe81/data/DBG-Detailed-GRI-index-Deutsche-Bo%CC%88rse-Group-AR-2022.pdf"],
            ["URL", None, "https://mpmaterials.com/downloads/MP_MATERIALS_2021_ESG_REPORT_A.pdf"],
        ],
        article=article,
        analytics_enabled=False,
        cache_examples=False,
    )
interface.queue().launch()