File size: 2,096 Bytes
fc5e5f2
3117482
 
897be90
822d7ea
7fab762
 
822d7ea
90592bd
 
df5250d
90592bd
 
 
 
 
 
 
 
 
822d7ea
 
 
 
 
 
 
c4b5495
 
 
 
 
9fd5245
c4b5495
b138465
 
822d7ea
3117482
 
 
 
 
 
 
8ccf021
 
 
 
 
 
a5554cc
2eb9ec0
a5554cc
8ccf021
 
 
 
 
 
 
 
c4b5495
2eb9ec0
c4b5495
8ccf021
 
 
428de1b
3117482
0c69a85
 
154bdd5
df5250d
641a65d
3117482
 
 
0c69a85
3117482
f5a3d2e
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import gradio as gr
from PyPDF2 import PdfReader
import os
from docx import Document as DocxDocument
from gradio_client import Client
from IPython.display import display
from IPython.display import Markdown

custom_css = """
#md {
    height: 450px;  
    font-size: 35px;
    background: black;
    padding: 20px;
    padding-top: 40px;
    color: white;
    border: 1 px solid #383838;
}
"""

def routing(message):
    client = Client("mgokg/SemanticRouting")
    result = client.predict(
		prompt=f"{message}",
		api_name="/predict"
    )
    return result

def mitteilung(input):
    client = Client("mgokg/Gemini2.0")
    result = client.predict(
		input_text=f"{input}",
		api_name="/generate_press_release"
    )
    return result

   
def process_pdf(file):
    # Read the PDF content
    pdf_reader = PdfReader(file.name)
    text = ""
    for page in pdf_reader.pages:
        text += page.extract_text()
    return text

def process_file(file):
    file_extension = file.name.split(".")[-1].lower()

    if file_extension == 'pdf':
        ocr_text = process_pdf(file)
        result = mitteilung(ocr_text)
        #display(Markdown(result))
        return result
        return ocr_text 

    elif file_extension == 'docx':
        docx_document = DocxDocument(file.name)
        text = ""
        for paragraph in docx_document.paragraphs:
            text += paragraph.text + "\n"

        result = mitteilung(text)
        #display(Markdown(result))
        return result
        return text
    #return [Document(text=text)]

with gr.Blocks(css=custom_css) as demo:
    gr.Markdown("### File upload", elem_classes="tab-header")
    with gr.Row():
        textoutput = gr.Markdown(label="Antwort", elem_id="md", value="#")
    with gr.Row():    
        text_output = gr.Textbox(label="")
    with gr.Row():    
        file_input = gr.File(label="Wähle eine PDF-Datei aus", type="filepath")
    with gr.Row():
        submit_button = gr.Button("upload")
    submit_button.click(process_file, inputs=file_input, outputs=[textoutput,text_output])
    
demo.launch(show_error=True)