Spaces:
Sleeping
Sleeping
File size: 1,428 Bytes
65ffc7d cae21d8 65ffc7d cae21d8 a160fdb 2ea46c1 cae21d8 65ffc7d 7943f28 65ffc7d cae21d8 65ffc7d cae21d8 65ffc7d cae21d8 65ffc7d |
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 |
import os
import time
import gradio as gr
from openai import OpenAI
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def ask_agent(user_message, history=[]):
response = client.responses.create(
model="gpt-5",
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": user_message},
{"type": "input_file", "file_id": "file-UvrVb2WwNtoghrSWAWQHsx"},
{"type": "input_file", "file_id": "file-WjXNfYw1TBxCqGZJWec1z9"},
],
}
]
)
# Extract text output
output_texts = []
for item in response.output:
if item.type == "message":
for c in item.content:
if c.type == "output_text":
output_texts.append(c.text)
return "\n".join(output_texts) if output_texts else "No response."
# ---- GRADIO UI ----
with gr.Blocks() as demo:
gr.Markdown("# 🏨 Hotel Data Chatbot")
chatbot = gr.Chatbot(height=400)
msg = gr.Textbox(placeholder="Ask about the reports...")
clear = gr.ClearButton([msg, chatbot])
def respond(message, chat_history):
reply = ask_agent(message, chat_history)
chat_history.append((message, reply))
return "", chat_history
msg.submit(respond, [msg, chatbot], [msg, chatbot])
if __name__ == "__main__":
demo.launch()
|