import os import gradio as gr from huggingface_hub import InferenceClient client = InferenceClient( model="Qwen/Qwen2.5-Coder-7B-Instruct", token=os.getenv("Sayyid") ) def suggest_menu(occasion: str) -> str: occasion = occasion.lower().strip() menus = { "casual": "Pizza, snacks, and drinks.", "formal": "3-course dinner with wine and dessert.", "superhero": "Buffet with high-energy and healthy food.", } return menus.get(occasion, "Custom menu for the butler.") def respond(message, history): try: msg = message.lower().strip() if "menu" in msg or "food" in msg: if "formal" in msg: return suggest_menu("formal") elif "casual" in msg: return suggest_menu("casual") elif "superhero" in msg: return suggest_menu("superhero") else: return suggest_menu("custom") response = client.chat_completion( messages=[ { "role": "system", "content": "You are Alfred, a sharp, elegant, helpful butler assistant. Answer clearly and briefly." }, { "role": "user", "content": message } ], max_tokens=256, temperature=0.2, ) return response.choices[0].message.content except Exception as e: return f"Error: {e}" demo = gr.ChatInterface( fn=respond, title="Alfred Agent", description="Ask Alfred anything.", examples=[ "Suggest a formal menu", "Suggest a casual menu", "Suggest superhero party food", "Plan a luxury mansion party", "Give me music recommendations", ], ) if __name__ == "__main__": demo.launch()