Spaces:
Sleeping
Sleeping
| 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() | |