ChatPDF-GUI / app.py
epochs-demos's picture
Update app.py
6f57eb8
raw
history blame
2.93 kB
import gradio as gr
import base64
from gpt_reader.pdf_reader import PaperReader
from gpt_reader.prompt import BASE_POINTS
import base64
import streamlit as st
with open("./logo.png", "rb") as f:
image_data = f.read()
image_base64 = base64.b64encode(image_data).decode("utf-8")
# Define the custom CSS styles
header_css = """
<style>
.header img {
margin-right: 10px;
width: 80px;
height: 50px;
}
.header p {
font-size: 14px;
}
</style>
"""
# Render the custom CSS
st.markdown(header_css, unsafe_allow_html=True)
# Render the header
header_html = f"""
<div class="header">
<img src='data:image/png;base64,{image_base64}' alt="Logo"/>
<p>Disclaimer: It is important to note that the purpose of this application is solely for demonstration purposes, showcasing the potential capabilities of AI systems. The information and results provided by the application should not be regarded as professional advice or a substitute for expert consultation in the relevant domain.
. Contact: [email protected] for full solution.</p>
</div>
"""
# Render the header HTML
st.markdown(header_html, unsafe_allow_html=True)
class GUI:
def __init__(self):
self.api_key = ""
self.session = ""
def analyse(self, api_key, pdf_file):
self.session = PaperReader(api_key, points_to_focus=BASE_POINTS)
return self.session.read_pdf_and_summarize(pdf_file)
def ask_question(self, question):
if self.session == "":
return "Please upload PDF file first!"
return self.session.question(question)
with gr.Blocks() as demo:
with gr.Tab("Upload PDF File"):
pdf_input = gr.File(label="PDF File")
api_input = gr.Textbox(label="OpenAI API Key")
result = gr.Textbox(label="PDF Summary")
upload_button = gr.Button("Start Analyse")
with gr.Tab("Ask question about your PDF"):
question_input = gr.Textbox(label="Your Question", placeholder="Authors of this paper?")
answer = gr.Textbox(label="Answer")
ask_button = gr.Button("Ask")
with gr.Accordion("About this project"):
gr.Markdown(
"""## CHATGPT-PAPER-READER📝
This repository provides a simple interface that utilizes the gpt-3.5-turbo
model to read academic papers in PDF format locally. You can use it to help you summarize papers,
create presentation slides, or simply fulfill tasks assigned by your supervisor.\n
[Github](https://github.com/talkingwallace/ChatGPT-Paper-Reader)""")
app = GUI()
upload_button.click(fn=app.analyse, inputs=[api_input, pdf_input], outputs=result)
ask_button.click(app.ask_question, inputs=question_input, outputs=answer)
if __name__ == "__main__":
iface = gr.Interface( title=title, description=description)
iface.launch()
demo.title = "CHATGPT-PAPER-READER"
demo.launch()