import gradio as gr import requests import os def chat(message, history): API_URL = "https://api-inference.huggingface.co/models/bitext/Mistral-7B-Customer-Support" headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"} # Format the message for the API payload = {"inputs": message} try: response = requests.post(API_URL, headers=headers, json=payload, timeout=30) if response.status_code == 200: result = response.json() if isinstance(result, list) and len(result) > 0: return result[0]["generated_text"] else: return "Sorry, I couldn't generate a response." else: return f"API Error: {response.status_code}" except Exception as e: return f"Error: {str(e)}" # Create Gradio interface demo = gr.ChatInterface( fn=chat, title="AI Customer Service Chatbot", description="Powered by Mistral-7B Customer Support (via Hugging Face API)", examples=[ ["How can I reset my password?"], ["What are your return policies?"], ["I need help with my order"], ["What payment methods do you accept?"] ] ) demo.launch()