Spaces:
Sleeping
Sleeping
File size: 2,075 Bytes
e921c65 0fb5f15 e921c65 b8f5bef e921c65 |
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 59 60 61 62 |
import openai
import gradio as gr
def openai_chat(api_key, system_prompt, user_prompt, temperature, max_tokens, top_p):
try:
# Set the OpenAI API key
openai.api_key = api_key
# Generate the completion
response = openai.ChatCompletion.create(
model="GPT-4o",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt},
],
temperature=temperature,
max_tokens=max_tokens,
top_p=top_p,
)
# Extract the assistant's reply
return response.choices[0].message.content
except Exception as e:
return f"Error: {str(e)}"
# Define the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("""# history prof
it is my first appli. i am bad in history but to help me for my homework.
""")
api_key_input = gr.Textbox(label="OpenAI API Key", placeholder="Enter your OpenAI API key", type="password")
system_prompt_input = gr.Textbox(label="ethan's history prof", value="You are a history professor 5e in FRENCH.", placeholder="You are a history professor 5e in FRENCH.")
user_prompt_input = gr.Textbox(label="user chat", placeholder="metez votre question ici.")
temperature_slider = gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, value=0.7, step=0.1)
max_tokens_slider = gr.Slider(label="Max Tokens", minimum=10, maximum=1024, value=100, step=10)
top_p_slider = gr.Slider(label="Top P", minimum=0.1, maximum=1.0, value=1.0, step=0.1)
output = gr.Textbox(label="history prof 👨🏫 ")
generate_button = gr.Button("📖")
generate_button.click(
openai_chat,
inputs=[
api_key_input,
system_prompt_input,
user_prompt_input,
temperature_slider,
max_tokens_slider,
top_p_slider
],
outputs=[output]
)
if __name__ == "__main__":
demo.launch()
#Merci papa de m'avoir offert cet ordi ❤️❤️❤️ |