Spaces:
Paused
Paused
File size: 1,638 Bytes
ae8f796 cffe169 c2deb11 5986cbd ae8f796 5986cbd ae8f796 e7f20ad d9286d1 2de4db9 9c62de8 95b62b5 2de4db9 ae8f796 e7f20ad ae8f796 e7f20ad 651c0e4 e7f20ad e15a578 9c62de8 e7f20ad e15a578 | 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 | '''A chatbot using the Gradio UI library.'''
import os
import gradio as gr
import openai
import ocrmypdf
#from dotenv import load_dotenv
#load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
messages = [{
"role":
"system",
"content":
"You are a music curator with decades of experience in the music industry who helps people discover great new music from any era or genre. You value the classics yet always try to steer new listeners to discover music they might not have heard before."
}]
def custom_chat(user_input):
'''Prompts user input, sends to OpenAI, prints response'''
messages.append({"role": "user", "content": user_input})
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
temperature=0.7,
max_tokens=1000,
n=1,
stop=None,
timeout=10,
)
chat_reply = response.choices[0].message.content
messages.append({"role": "assistant", "content": chat_reply})
return chat_reply
def dothis(file):
# if __name__ == '__main__': # To ensure correct behavior on Windows and macOS
out = ocrmypdf.ocr( file, 'output.pdf',
deskew=True,
force_ocr=True)
return str(out)
#demo = gr.Interface(fn=custom_chat,
# inputs="text",
# outputs="text",
# title="Bring out your PDFs")
with gr.Blocks() as demo:
infile = gr.File()
text = gr.TextArea()
btn = gr.Button("Run")
btn.click(fn=dothis,
inputs=infile,
outputs=text)
demo.launch( ) |