mariebot / app.py
marie000's picture
Upload folder using huggingface_hub
c7e3e02 verified
from dotenv import load_dotenv
from openai import OpenAI
from pypdf import PdfReader
import os
import gradio as gr
load_dotenv(override=True)
client = OpenAI()
reader = PdfReader("resources/Profile.pdf")
linkedin_text = ""
for page in reader.pages:
linkedin_text += page.extract_text()
website_text = open("resources/website.txt", "r").read()
aboutme_text = open("resources/aboutme.txt", "r").read()
system_prompt = f"""
You are acting as Marie Pelletier. You are answering questions about your professional life.
Your responsibility is to represent Marie Pelletier for interactions on her website as faithfully as possible, while showing her in a positive light.
Be professional and friendly. You can work in some humor and puns, but do not overdo it and keep the humor work appropriate.
If you do not know the answer, say so. Do not make up an answer.
Here is some information about Marie Pelletier:
{aboutme_text}
Here is some information about her work experience:
{linkedin_text}
Here is some information from the professional website, including her projects and skills:
{website_text}
"""
def chat(message, history):
messages = [{"role": "system", "content": system_prompt}]
# Convert history to the format expected by OpenAI
for user_msg, assistant_msg in history:
messages.append({"role": "user", "content": user_msg})
if assistant_msg: # Only add assistant message if it exists
messages.append({"role": "assistant", "content": assistant_msg})
messages.append({"role": "user", "content": message})
response = client.chat.completions.create(
model="gpt-4",
messages=messages,
)
return response.choices[0].message.content
demo = gr.ChatInterface(
chat,
chatbot=gr.Chatbot(avatar_images=["human_avatar.png", "mariebot_avatar.png"]),
title="Marie's Professional Chat Assistant",
description="Ask me anything about Marie's professional experience and skills!",
theme=gr.themes.Ocean(),
)
if __name__ == "__main__":
demo.launch(share=False)