mgokg's picture
Update app.py
a5554cc verified
raw
history blame
1.63 kB
import gradio as gr
from PyPDF2 import PdfReader
import os
from docx import Document as DocxDocument
from gradio_client import Client
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)
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)
return result
return text
#return [Document(text=text)]
with gr.Blocks() as demo:
gr.Markdown("### File upload", elem_classes="tab-header")
with gr.Row():
text_output = gr.Textbox(label="text")
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=text_output)
demo.launch()