File size: 474 Bytes
806d7c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as gr

from utils.chatgpt import ChatGPTAPI
from utils.read_pdf import read_pdf


def process(api_key: str = '', prompt: str = '', file=None) -> str:
    chatgpt = ChatGPTAPI(api_key, max_input_length=1024)

    pdf_contents = read_pdf(file.name)
    pdf_str = '\n'.join(pdf_contents)
    content = prompt + '\n' + pdf_str
    response = chatgpt(content)
    return response


gr.Interface(fn=process, inputs=["text", "text", "file"], outputs="text").launch()