Create app.py
Browse filesHERACLEA Natural Intelligence - семејна AI асистентка со македонски поддршка
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import sqlite3
|
3 |
+
import datetime
|
4 |
+
import os
|
5 |
+
|
6 |
+
# HERACLEA Natural Intelligence - Семејна AI Асистентка
|
7 |
+
class HeracleaNI:
|
8 |
+
def __init__(self):
|
9 |
+
self.db = sqlite3.connect('heraclea.db', check_same_thread=False)
|
10 |
+
self.init_db()
|
11 |
+
|
12 |
+
def init_db(self):
|
13 |
+
cursor = self.db.cursor()
|
14 |
+
cursor.execute('''CREATE TABLE IF NOT EXISTS conversations
|
15 |
+
(id INTEGER PRIMARY KEY, message TEXT, response TEXT,
|
16 |
+
timestamp DATETIME)''')
|
17 |
+
self.db.commit()
|
18 |
+
|
19 |
+
def save_conversation(self, message, response):
|
20 |
+
cursor = self.db.cursor()
|
21 |
+
cursor.execute('''INSERT INTO conversations (message, response, timestamp)
|
22 |
+
VALUES (?, ?, ?)''',
|
23 |
+
(message, response, datetime.datetime.now()))
|
24 |
+
self.db.commit()
|
25 |
+
|
26 |
+
def get_response(self, message):
|
27 |
+
# Македонски одговори
|
28 |
+
if "здраво" in message.lower():
|
29 |
+
return "🏛️ Здраво! Јас сум HERACLEA, вашата семејна AI асистентка!"
|
30 |
+
elif "како си" in message.lower():
|
31 |
+
return "Одлично! Учам и се развивам секој ден заедно со вас!"
|
32 |
+
elif "што можеш" in message.lower():
|
33 |
+
return "Можам да памтам разговори, да учам од документи и да ви помагам со секојдневни задачи!"
|
34 |
+
else:
|
35 |
+
return f"HERACLEA: {message} - Учам од секоја ваша порака!"
|
36 |
+
|
37 |
+
# Креирај HERACLEA инстанца
|
38 |
+
heraclea = HeracleaNI()
|
39 |
+
|
40 |
+
def chat_with_heraclea(message, history):
|
41 |
+
if message.strip():
|
42 |
+
response = heraclea.get_response(message)
|
43 |
+
heraclea.save_conversation(message, response)
|
44 |
+
history.append((message, response))
|
45 |
+
return history, ""
|
46 |
+
return history, ""
|
47 |
+
|
48 |
+
# Gradio интерфејс
|
49 |
+
with gr.Blocks(title="🏛️ HERACLEA Natural Intelligence") as demo:
|
50 |
+
gr.HTML("<h1>🏛️ HERACLEA Natural Intelligence</h1>")
|
51 |
+
gr.HTML("<p>Вашата семејна AI асистентка - учи, памти и расте заедно со вас</p>")
|
52 |
+
|
53 |
+
chatbot = gr.Chatbot(height=400)
|
54 |
+
msg = gr.Textbox(label="Пишете порака до HERACLEA:",
|
55 |
+
placeholder="Здраво HERACLEA...",
|
56 |
+
lines=1)
|
57 |
+
|
58 |
+
msg.submit(chat_with_heraclea, [msg, chatbot], [chatbot, msg])
|
59 |
+
|
60 |
+
# Статистики
|
61 |
+
gr.HTML("<p style='color: #666; font-size: 12px;'>HERACLEA памти секој разговор и учи од вас!</p>")
|
62 |
+
|
63 |
+
if __name__ == "__main__":
|
64 |
+
demo.launch()
|