import gradio as gr import base64 import os api_key = os.getenv('API_KEY') def predict(input, file_input): print("input:", input) print("file_input:", file_input.name) from gradio_client import Client client = Client(api_key) extract_result = client.predict( input, file_input.name, fn_index=1 ) if extract_result: print(extract_result) return extract_result else: return "Too many user, please wait a monument!" def view_pdf(pdf_file): with open(pdf_file.name, 'rb') as f: pdf_data = f.read() # print("pdf_file", pdf_file) # pdf_data = pdf_file b64_data = base64.b64encode(pdf_data).decode('utf-8') # print("b64_data", b64_data) return f"" en_1 = ["""could you please help me extract the information of 'title'/'journal'/'year'/'author'/'institution'/'email' from the previous content in a markdown table format? If any of this information was not available in the paper, please replaced it with the string `""`, If the property contains multiple entities, please use a list to contain. """] en_2 = ["""could you please help me extract the information of 'title'/'journal'/'year'/'author'/'institution'/'email' from the previous content in a json format? If any of this information was not available in the paper, please replaced it with the string `""`, If the property contains multiple entities, please use a list to contain. """] examples = [en_1, en_2] with gr.Blocks(title="ChatPaperGPT") as demo: gr.Markdown( '''
How to use:
#1: Upload your pdf.
#2: Click the View PDF button to view it.
#3: Enter your extraction prompt in the input box (of course, you can click example to test).
#4: Click Generate to extract, and the extracted information will be displayed in markdown form.