hinojosachapel's picture
Upload folder using huggingface_hub
e28330b verified
raw
history blame
1.55 kB
from openai import OpenAI
import gradio as gr
openai_apikey = "sk-proj-JW9oMGO1QmwnOxQ3vUA8T3BlbkFJO2zo3KLERLeds7HJmt6y"
client = OpenAI(api_key = openai_apikey)
thread = client.beta.threads.create()
def get_answer(question):
message = client.beta.threads.messages.create(
thread_id = thread.id,
role = "user",
content = question
)
run = client.beta.threads.runs.create_and_poll(
thread_id = thread.id,
assistant_id = "asst_LgX8lE9erZR3ktgzOvkWNAQ8",
instructions = "Your name is Bossard ChatGPT. You enable access to Bossard technical knowledge in an interactive and targeted way. You act like an experienced Bossard engineer and can advise with skillful hints in the entirety and provide relevant further information. I want the answer you give to be more or less 100 words maximum if necessary. Try responding with a list, a short answer or a step-by-step guide if you feel like you should give an answer like that for the question."
)
messages = client.beta.threads.messages.list(
thread_id = thread.id
)
response = messages.data[0].content[0].text.value
return response
with gr.Blocks() as demo:
gr.Markdown(
"""
# Bossard ChatGPT
### PoC with OpenAI GPT4o
""")
interface = gr.Interface(
fn = get_answer,
inputs = [gr.Textbox(placeholder="Enter the question", label="Question")],
outputs = [gr.Markdown()]
)
demo.launch(server_port=7860)
# demo.launch(share=True, server_port=7860)