MatD / old_app.py
AnnaAneta's picture
Rename app.py to old_app.py
4f5d303 verified
Raw History Blame Contribute Delete
930 Bytes
import gradio as gr
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"]) # wymaga zmiennej środowiskowej OPENAI_API_KEY
def chat_with_gpt(message, history):
messages = [{"role": "system", "content": "Jesteś pomocnym asystentem."}]
for human, ai in history:
messages.append({"role": "user", "content": human})
messages.append({"role": "assistant", "content": ai})
messages.append({"role": "user", "content": message})
response = client.chat.completions.create(
# model="gpt-4o-mini",
model="gpt-4.1-mini",
messages=messages,
)
return response.choices[0].message.content
with gr.Blocks() as demo:
gr.Markdown("## Mój pierwszy interfejs z Gradio")
gr.ChatInterface(fn=chat_with_gpt)
#def greet(name):
# return "Hello " + name + "!!"
#demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()