Spaces:
Sleeping
Sleeping
Added correct deployment
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from openai import AzureOpenAI
|
|
| 5 |
|
| 6 |
# Redis Cloud connection
|
| 7 |
redis_client = redis.Redis(
|
| 8 |
-
host=
|
| 9 |
port=12628,
|
| 10 |
decode_responses=True,
|
| 11 |
username="default",
|
|
@@ -15,10 +15,10 @@ redis_client = redis.Redis(
|
|
| 15 |
# Azure OpenAI client
|
| 16 |
client = AzureOpenAI(
|
| 17 |
api_key=os.getenv("AZURE_OPENAI_API_KEY").strip(),
|
| 18 |
-
api_version="2025-01-01-preview",
|
| 19 |
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT").strip()
|
| 20 |
)
|
| 21 |
-
DEPLOYMENT_NAME = "
|
| 22 |
|
| 23 |
def chat_with_ai(user_input):
|
| 24 |
if not user_input:
|
|
@@ -46,18 +46,19 @@ def chat_with_ai(user_input):
|
|
| 46 |
with gr.Blocks(title="Azure OpenAI + Redis Cloud Chat") as demo:
|
| 47 |
gr.Markdown("# 💬 Azure OpenAI + Redis Cloud Demo")
|
| 48 |
with gr.Row():
|
| 49 |
-
chatbot = gr.Chatbot()
|
| 50 |
with gr.Row():
|
| 51 |
msg = gr.Textbox(placeholder="Type your message here...")
|
| 52 |
send = gr.Button("Send")
|
| 53 |
|
| 54 |
def respond(message, history):
|
| 55 |
bot_reply = chat_with_ai(message)
|
| 56 |
-
history.append(
|
|
|
|
| 57 |
return history, ""
|
| 58 |
|
| 59 |
send.click(respond, [msg, chatbot], [chatbot, msg])
|
| 60 |
msg.submit(respond, [msg, chatbot], [chatbot, msg])
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
| 63 |
-
demo.launch(
|
|
|
|
| 5 |
|
| 6 |
# Redis Cloud connection
|
| 7 |
redis_client = redis.Redis(
|
| 8 |
+
host="redis-12628.c14.us-east-1-2.ec2.redns.redis-cloud.com",
|
| 9 |
port=12628,
|
| 10 |
decode_responses=True,
|
| 11 |
username="default",
|
|
|
|
| 15 |
# Azure OpenAI client
|
| 16 |
client = AzureOpenAI(
|
| 17 |
api_key=os.getenv("AZURE_OPENAI_API_KEY").strip(),
|
| 18 |
+
api_version="2025-01-01-preview", # valid API version
|
| 19 |
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT").strip()
|
| 20 |
)
|
| 21 |
+
DEPLOYMENT_NAME = "gpt-4.1" # must match your Azure deployment name!
|
| 22 |
|
| 23 |
def chat_with_ai(user_input):
|
| 24 |
if not user_input:
|
|
|
|
| 46 |
with gr.Blocks(title="Azure OpenAI + Redis Cloud Chat") as demo:
|
| 47 |
gr.Markdown("# 💬 Azure OpenAI + Redis Cloud Demo")
|
| 48 |
with gr.Row():
|
| 49 |
+
chatbot = gr.Chatbot(type="messages")
|
| 50 |
with gr.Row():
|
| 51 |
msg = gr.Textbox(placeholder="Type your message here...")
|
| 52 |
send = gr.Button("Send")
|
| 53 |
|
| 54 |
def respond(message, history):
|
| 55 |
bot_reply = chat_with_ai(message)
|
| 56 |
+
history.append({"role": "user", "content": message})
|
| 57 |
+
history.append({"role": "assistant", "content": bot_reply})
|
| 58 |
return history, ""
|
| 59 |
|
| 60 |
send.click(respond, [msg, chatbot], [chatbot, msg])
|
| 61 |
msg.submit(respond, [msg, chatbot], [chatbot, msg])
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|
| 64 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, debug=True,pwa=True)
|