ArBaltee commited on
Commit
9fc9cb0
·
verified ·
1 Parent(s): 96fa637

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -113
app.py CHANGED
@@ -49,125 +49,63 @@ def generate_response(user_input):
49
  print(f"Error generating response: {e}")
50
  return f"Sorry, I encountered an error while generating a response. Please try again later."
51
 
52
- # For demonstration purposes, we'll use a simpler model approach
53
- # that doesn't require an API key but still provides responses
54
- def get_ai_response(message):
55
- """Generate a response using a local model"""
56
- # Check if asking about creator/CEO
57
- if any(keyword in message.lower() for keyword in ["who made you", "who created you", "creator", "ceo", "who owns"]):
58
- return "I was created by AR.BALTEE, who is also the CEO of NORTHERN_AI."
59
-
60
- # Simple response generation (replace this with actual model inference)
61
- responses = [
62
- "I understand your question about {}. Based on my knowledge, I would say that...",
63
- "Thanks for asking about {}. Here's what I know on this topic...",
64
- "Regarding {}, I can provide some information...",
65
- "I've analyzed your question about {} and here's my perspective...",
66
- "When it comes to {}, there are several important points to consider..."
67
- ]
68
-
69
- # Extract key topic from message
70
- topic = message.split()[0] if len(message.split()) > 0 else "that"
71
-
72
- # Add a slight delay to simulate processing
73
- time.sleep(0.5)
74
-
75
- return random.choice(responses).format(topic)
76
-
77
- # Custom CSS for styling
78
- css = """
79
- .gradio-container {
80
- max-width: 800px !important;
81
- margin: 0 auto !important;
82
- }
83
- #header-container {
84
- display: flex !important;
85
- align-items: center !important;
86
- margin-bottom: 1rem !important;
87
- background-color: black !important;
88
- padding: 0.5rem 1rem !important;
89
- border-bottom: 1px solid #eee !important;
90
- }
91
- #logo {
92
- background-color: #0066ff !important;
93
- color: white !important;
94
- border-radius: 50% !important;
95
- width: 32px !important;
96
- height: 32px !important;
97
- display: flex !important;
98
- align-items: center !important;
99
- justify-content: center !important;
100
- font-weight: bold !important;
101
- margin-right: 10px !important;
102
- }
103
- #title {
104
- margin: 0 !important;
105
- font-size: 18px !important;
106
- font-weight: 600 !important;
107
- }
108
- #footer {
109
- font-size: 12px !important;
110
- color: #666 !important;
111
- text-align: center !important;
112
- margin-top: 1rem !important;
113
- padding: 0.5rem !important;
114
- }
115
- """
116
-
117
  # Create Gradio interface
118
- with gr.Blocks(css=css) as demo:
119
- with gr.Column():
120
- # Custom header
121
- with gr.Row(elem_id="header-container"):
122
- gr.HTML('<div id="logo">N</div>')
123
- gr.HTML('<h1 id="title">NORTHERN_AI</h1>')
124
-
125
- # Chat interface
126
- chatbot = gr.Chatbot(
127
- height=400,
128
- show_label=False,
129
- )
130
-
131
- with gr.Row():
132
  msg = gr.Textbox(
133
- placeholder="Message NORTHERN_AI...",
134
- show_label=False,
135
- container=False
136
  )
137
- submit_btn = gr.Button("Send")
138
-
139
- gr.HTML('<div id="footer">Powered by open-source technology</div>')
 
 
 
 
 
 
 
 
140
 
141
- # State for tracking conversation
142
- state = gr.State([])
143
 
144
- # Functions
145
- def respond(message, chat_history):
146
- if message == "":
147
- return "", chat_history
148
-
149
- # Add user message to history
150
- chat_history.append((message, None))
151
-
152
- try:
153
- # Generate response
154
- bot_message = get_ai_response(message)
155
-
156
- # Update last message with bot response
157
- chat_history[-1] = (message, bot_message)
158
-
159
- return "", chat_history
160
- except Exception as e:
161
- print(f"Error generating response: {e}")
162
- # Remove failed message attempt
163
- chat_history.pop()
164
- # Return error message
165
- return "", chat_history
166
 
167
- # Set up event handlers
168
- msg.submit(respond, [msg, state], [msg, chatbot])
169
- submit_btn.click(respond, [msg, state], [msg, chatbot])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
- # Launch the app
172
  if __name__ == "__main__":
173
  demo.launch()
 
49
  print(f"Error generating response: {e}")
50
  return f"Sorry, I encountered an error while generating a response. Please try again later."
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  # Create Gradio interface
53
+ with gr.Blocks(title="NORTHERN_AI") as demo:
54
+ gr.Markdown("# NORTHERN_AI by AR.BALTEE")
55
+ gr.Markdown("### Your AI assistant powered by NORTHERN 0.1")
56
+
57
+ with gr.Row():
58
+ with gr.Column(scale=4):
59
+ chatbot = gr.Chatbot(label="Conversation", height=400)
 
 
 
 
 
 
 
60
  msg = gr.Textbox(
61
+ label="Type your message",
62
+ placeholder="Ask NORTHERN_AI something...",
63
+ lines=2
64
  )
65
+
66
+ with gr.Row():
67
+ submit = gr.Button("Send", variant="primary")
68
+ clear = gr.Button("Clear", variant="secondary")
69
+
70
+ # Keep track of conversation history
71
+ conversation_history = gr.State([])
72
+
73
+ def user_input(message, history):
74
+ if not message:
75
+ return "", history
76
 
77
+ # Get AI response
78
+ ai_response = generate_response(message)
79
 
80
+ # Update history
81
+ history.append((message, ai_response))
82
+ return "", history
83
+
84
+ def clear_conversation():
85
+ return [], []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
+ submit.click(
88
+ user_input,
89
+ inputs=[msg, conversation_history],
90
+ outputs=[msg, chatbot]
91
+ )
92
+
93
+ msg.submit(
94
+ user_input,
95
+ inputs=[msg, conversation_history],
96
+ outputs=[msg, chatbot]
97
+ )
98
+
99
+ clear.click(
100
+ clear_conversation,
101
+ outputs=[chatbot, conversation_history]
102
+ )
103
+
104
+ gr.HTML("""
105
+ <div style="text-align: center; margin-top: 20px;">
106
+ <p>Created by AR.BALTEE - NORTHERN_AI © 2025</p>
107
+ </div>
108
+ """)
109
 
 
110
  if __name__ == "__main__":
111
  demo.launch()