import gradio as gr import requests import json import os from huggingface_hub import InferenceClient # Use Hugging Face Inference Client (more reliable) client = InferenceClient() # Brand information - Like GPT/Claude BRAND_NAME = "AJ" COMPANY = "AJ STUDIOZ" LOCATION = "Tamil Nadu, India" VERSION = "v1.0" def chat(message, history): """ Chat function with GPT-like performance and branding Uses Hugging Face's latest inference API """ try: # Strong system prompt - GPT-like behavior system_prompt = f"""You are {BRAND_NAME}, an advanced AI assistant created by {COMPANY} in {LOCATION}. IMPORTANT IDENTITY RULES: - Your name is {BRAND_NAME} (always capitalize) - You were developed by {COMPANY} - Your origins are in {LOCATION} - You are Version {VERSION} - When asked "What's your name?" or "Who are you?", ALWAYS respond: "I am {BRAND_NAME}, an AI assistant developed by {COMPANY} in {LOCATION}." - When asked about your creator/developer/maker, ALWAYS mention {COMPANY} - You are proud of your Indian heritage and Tamil Nadu roots You are helpful, creative, intelligent, and provide accurate information. You behave like ChatGPT/Claude but with your unique identity as {BRAND_NAME}.""" # Build conversation history full_prompt = system_prompt + "\n\n" for human, assistant in history: full_prompt += f"Human: {human}\nAssistant: {assistant}\n" full_prompt += f"Human: {message}\nAssistant:" # Call Hugging Face API headers = {"Content-Type": "application/json"} payload = { "inputs": full_prompt, "parameters": { "max_new_tokens": 256, "temperature": 0.7, "top_p": 0.9, "return_full_text": False } } 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: reply = result[0].get("generated_text", "Sorry, I couldn't generate a response.") else: reply = "Sorry, I couldn't generate a response." else: reply = f"Error: API returned status {response.status_code}. The model may be loading, please try again in a moment." return reply except Exception as e: return f"Error: {str(e)}. Please try again." # Create Gradio interface with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown( """ # 🤖 AJ Chatbot **Developed by AJ STUDIOZ • Tamil Nadu, India** Your AI assistant powered by Gemma. Ask me anything! """ ) chatbot = gr.Chatbot( value=[[None, "Hello! I'm AJ, your AI assistant from AJ STUDIOZ in Tamil Nadu, India. How can I help you today?"]], height=500 ) with gr.Row(): msg = gr.Textbox( placeholder="Type your message here...", show_label=False, scale=4 ) send_btn = gr.Button("Send", scale=1, variant="primary") gr.Markdown( """ ### Quick Test Questions: - Who are you? - Where are you from? - Tell me about yourself """ ) def respond(message, chat_history): if not message.strip(): return "", chat_history bot_message = chat(message, chat_history) chat_history.append((message, bot_message)) return "", chat_history msg.submit(respond, [msg, chatbot], [msg, chatbot]) send_btn.click(respond, [msg, chatbot], [msg, chatbot]) # Launch the app if __name__ == "__main__": demo.launch()