File size: 3,825 Bytes
2de5186
 
 
b5eb6c6
 
2de5186
b5eb6c6
 
 
 
 
 
 
 
2de5186
 
 
b5eb6c6
 
2de5186
 
b5eb6c6
 
 
 
 
 
 
 
 
 
 
 
 
 
2de5186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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()