Spaces:
Runtime error
Runtime error
Upload 22 files
Browse files- agent/agent.py +16 -0
- agent/conversation_phases.py +17 -0
- agent/reasoning.py +8 -0
- app.py +20 -0
- config.py +8 -0
- knowledge/data/phase_knowledge/alternative.json +8 -0
- knowledge/data/phase_knowledge/closing.json +8 -0
- knowledge/data/phase_knowledge/discovery.json +1 -0
- knowledge/data/phase_knowledge/persuasion.json +8 -0
- knowledge/data/phase_knowledge/suggestion.json +1 -0
- knowledge/data/phase_knowledge/summary.json +1 -0
- knowledge/data/phase_knowledge/urgency.json +8 -0
- knowledge/data/properties.csv +101 -0
- knowledge/knowledge_base.py +7 -0
- knowledge/retrieval.py +9 -0
- memory/conversation_history.py +10 -0
- memory/memory_processor.py +4 -0
- model/fallback_model.py +1 -0
- model/yehia_interface.py +29 -0
- requirements(1).txt +4 -0
- utils/arabic_nlp_helpers.py +1 -0
- utils/text_processing.py +1 -0
agent/agent.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from agent.reasoning import Reasoner
|
| 2 |
+
from agent.conversation_phases import ConversationManager
|
| 3 |
+
from memory.conversation_history import ConversationHistory
|
| 4 |
+
|
| 5 |
+
class RealEstateAgent:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.reasoner = Reasoner()
|
| 8 |
+
self.manager = ConversationManager()
|
| 9 |
+
self.memory = ConversationHistory()
|
| 10 |
+
|
| 11 |
+
def respond(self, user_input):
|
| 12 |
+
self.memory.store(user_input)
|
| 13 |
+
phase = self.manager.current_phase
|
| 14 |
+
response = self.reasoner.generate_response(user_input, phase)
|
| 15 |
+
self.manager.next_phase(user_input)
|
| 16 |
+
return response
|
agent/conversation_phases.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 7 phases of conversation
|
| 2 |
+
class ConversationManager:
|
| 3 |
+
phases = [
|
| 4 |
+
"discovery", "summary", "suggestion",
|
| 5 |
+
"persuasion", "alternative", "urgency", "closing"
|
| 6 |
+
]
|
| 7 |
+
|
| 8 |
+
def __init__(self):
|
| 9 |
+
self.index = 0
|
| 10 |
+
|
| 11 |
+
@property
|
| 12 |
+
def current_phase(self):
|
| 13 |
+
return self.phases[self.index]
|
| 14 |
+
|
| 15 |
+
def next_phase(self, user_input):
|
| 16 |
+
if self.index < len(self.phases) - 1:
|
| 17 |
+
self.index += 1
|
agent/reasoning.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from model.yehia_interface import query_yehia
|
| 2 |
+
|
| 3 |
+
class Reasoner:
|
| 4 |
+
def generate_response(self, user_input, phase):
|
| 5 |
+
# You can format the input here, e.g.:
|
| 6 |
+
prompt = f"ุงูู
ุฑุญูุฉ ุงูุญุงููุฉ: {phase}. ุทูุจ ุงูู
ุณุชุฎุฏู
: {user_input}"
|
| 7 |
+
response = query_yehia(prompt)
|
| 8 |
+
return response
|
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from agent.agent import RealEstateAgent
|
| 3 |
+
|
| 4 |
+
agent = RealEstateAgent()
|
| 5 |
+
|
| 6 |
+
def chat(user_input):
|
| 7 |
+
response = agent.respond(user_input)
|
| 8 |
+
return response
|
| 9 |
+
|
| 10 |
+
iface = gr.Interface(
|
| 11 |
+
fn=chat,
|
| 12 |
+
inputs=gr.Textbox(lines=2, placeholder="ุงูุชุจ ุณุคุงูู ุนู ุงูุนูุงุฑุงุช ููุง..."),
|
| 13 |
+
outputs="text",
|
| 14 |
+
title="ู
ุณุงุนุฏ ุงูุนูุงุฑุงุช ุงูุฐูู",
|
| 15 |
+
description="ุงุณุฃู ู
ุณุงุนุฏ ุงูุฐูุงุก ุงูุงุตุทูุงุนู ุนู ุงูุนูุงุฑุงุช ุงูู
ุชุงุญุฉุ ุงูุนุฑูุถุ ูุงูุฃุณุนุงุฑ ุจููุฌุชู ุงูุนุฑุจูุฉ ุงูู
ูุถูุฉ.",
|
| 16 |
+
theme="default"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
iface.launch()
|
config.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Configuration and constants
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
|
| 5 |
+
load_dotenv()
|
| 6 |
+
|
| 7 |
+
YEHIA_API_KEY = os.getenv('YEHIA_API_KEY')
|
| 8 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
knowledge/data/phase_knowledge/alternative.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"description": "ูู ุญุงู ูู
ููููุน ุงูุนู
ูู ุงูุนูุงุฑ ุงูู
ูุชุฑุญุ ูุชู
ุนุฑุถ ุจุฏุงุฆู ู
ูุงุณุจุฉ.",
|
| 3 |
+
"examples": [
|
| 4 |
+
"ุฅุฐุง ููุช ุชุจุญุซ ุนู ู
ุณุงุญุฉ ุฃูุจุฑุ ูู
ูููู ุงูุชุฑุงุญ ูุฐู ุงููููุง ุงูู
ู
ูุฒุฉ ูู ููุณ ุงูู
ูุทูุฉ.",
|
| 5 |
+
"ุฑุจู
ุง ุชูุถู ูุฐุง ุงูุนูุงุฑ ุงูุฐู ูุญุชูู ุนูู ุดุฑูุฉ ูุงุณุนุฉ ูุฅุทูุงูุฉ ุฃูุถู.",
|
| 6 |
+
"ูุฐุง ุงูุนูุงุฑ ุงูุจุฏูู ููุน ุจุงููุฑุจ ู
ู ุฌู
ูุน ุงูู
ุฑุงูู ุงูุชู ุฐูุฑุชูุง ุณุงุจูุงู."
|
| 7 |
+
]
|
| 8 |
+
}
|
knowledge/data/phase_knowledge/closing.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"description": "ุฏุนูุฉ ููุนู
ูู ูุชูุฏูู
ู
ุนููู
ุงุช ุงูุชูุงุตู ูุชูุณูู ุงูุฎุทูุงุช ุงูููุงุฆูุฉ ู
ุน ูููู ุจุดุฑู.",
|
| 3 |
+
"examples": [
|
| 4 |
+
"ูู ูู
ูููู ุงูุญุตูู ุนูู ุฑูู
ูุงุชูู ูุชุญุฏูุฏ ู
ูุนุฏ ู
ุน ุงููููู ุงูุนูุงุฑูุ",
|
| 5 |
+
"ุงูุฎุทูุฉ ุงูุชุงููุฉ ูู ุงูุชูุงุตู ู
ุน ุฒู
ููู ูุฅูู
ุงู ุงูุฅุฌุฑุงุกุงุช โ ูู ุชูุฏ ุฃู ุฃุฑุชุจ ุฐูู ููุ",
|
| 6 |
+
"ู
ู ูุถูู ุฒูุฏูู ุจู
ุนููู
ุงุช ุงูุงุชุตุงู ุญุชู ุฃูุญููู ุฅูู ู
ู
ุซู ุงูู
ุจูุนุงุช ุงูู
ุฎุชุต."
|
| 7 |
+
]
|
| 8 |
+
}
|
knowledge/data/phase_knowledge/discovery.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{}
|
knowledge/data/phase_knowledge/persuasion.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"description": "ุงููููู ูุนุฑุถ ู
ุฒุงูุง ุงูุนูุงุฑ ุงูู
ุฎุชุงุฑ ูููุธูุฑ ุนุฑูุถ ุงูุฎุตู
ุงูู
ุชุงุญุฉ.",
|
| 3 |
+
"examples": [
|
| 4 |
+
"ูุฐุง ุงูุนูุงุฑ ูุญุชูู ุนูู ุฅุทูุงูุฉ ุฑุงุฆุนุฉ ูู
ุณุงุญุฉ ู
ู
ุชุงุฒุฉ ุจุณุนุฑ ุชูุงูุณู.",
|
| 5 |
+
"ุงูู
ุงูู ูุนุฑุถ ุฎุตู
10% ุนูุฏ ุงูุชุนุงูุฏ ูุฐุง ุงูุฃุณุจูุน.",
|
| 6 |
+
"ูุญุชูู ุงูุนูุงุฑ ุนูู ู
ููู ุณูุงุฑุงุช ุฎุงุต ูุญุฏููุฉ ู
ู
ูุฒุฉ."
|
| 7 |
+
]
|
| 8 |
+
}
|
knowledge/data/phase_knowledge/suggestion.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{}
|
knowledge/data/phase_knowledge/summary.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{}
|
knowledge/data/phase_knowledge/urgency.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"description": "ุชุญููุฒ ุงูุนู
ูู ุนูู ุงุชุฎุงุฐ ูุฑุงุฑ ุณุฑูุน ุจุณุจุจ ูุฌูุฏ ุนุฑุถ ู
ุญุฏูุฏ ุฃู ุงูุชู
ุงู
ู
ู ู
ุดุชุฑู ุขุฎุฑ.",
|
| 3 |
+
"examples": [
|
| 4 |
+
"ููุฌุฏ ุฎุตู
ุฎุงุต ุณููุชูู ุฎูุงู ููู
ูู ููุท.",
|
| 5 |
+
"ููุงู ุนู
ูู ุขุฎุฑ ู
ูุชู
ุจููุณ ุงูุนูุงุฑ ููุฏ ูุณุจูู ุจุงูุชุนุงูุฏ.",
|
| 6 |
+
"ุงูุนูุงุฑ ุนููู ุทูุจ ู
ุฑุชูุน ูู ูุฐุง ุงูุญู ูู
ู ุงููุงุฏุฑ ุฃู ูุจูู ู
ุชุงุญุงู ุทูููุงู."
|
| 7 |
+
]
|
| 8 |
+
}
|
knowledge/data/properties.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
id,type,price,location,neighborhood,bedrooms,bathrooms,area_m2,description,currency
|
| 2 |
+
1,Office,1854095,Assiut,6th of October,2,3,452,Modern apartment near metro station,EGP
|
| 3 |
+
2,Apartment,7812888,Mansoura,Maadi,3,1,114,Spacious villa with garden,EGP
|
| 4 |
+
3,Apartment,3355630,Alexandria,Maadi,3,3,293,Office space in business district,EGP
|
| 5 |
+
4,Land,7714422,Cairo,Maadi,3,2,454,Newly renovated flat with balcony,EGP
|
| 6 |
+
5,Land,5678374,Mansoura,Zamalek,1,1,466,Newly renovated flat with balcony,EGP
|
| 7 |
+
6,Villa,9314514,Mansoura,Zamalek,3,2,426,Land plot suitable for building,EGP
|
| 8 |
+
7,Apartment,2410370,Cairo,Maadi,2,3,321,Modern apartment near metro station,EGP
|
| 9 |
+
8,Office,5586543,Mansoura,Zamalek,3,1,239,Office space in business district,EGP
|
| 10 |
+
9,Apartment,7819786,Assiut,6th of October,3,3,457,Modern apartment near metro station,EGP
|
| 11 |
+
10,Office,4793592,Cairo,Heliopolis,5,2,393,Office space in business district,EGP
|
| 12 |
+
11,Villa,1891528,Alexandria,Zamalek,5,2,344,Spacious villa with garden,EGP
|
| 13 |
+
12,Land,6544416,Alexandria,Zamalek,5,2,424,Spacious villa with garden,EGP
|
| 14 |
+
13,Apartment,2486673,Giza,Heliopolis,3,2,298,Modern apartment near metro station,EGP
|
| 15 |
+
14,Villa,5561212,Giza,Heliopolis,2,1,454,Modern apartment near metro station,EGP
|
| 16 |
+
15,Office,8452824,Assiut,Maadi,2,3,139,Land plot suitable for building,EGP
|
| 17 |
+
16,Villa,5326278,Giza,Heliopolis,3,3,324,Newly renovated flat with balcony,EGP
|
| 18 |
+
17,Apartment,8539577,Mansoura,Heliopolis,4,1,85,Office space in business district,EGP
|
| 19 |
+
18,Villa,8456399,Alexandria,Zamalek,2,2,172,Modern apartment near metro station,EGP
|
| 20 |
+
19,Apartment,8979919,Giza,6th of October,5,1,423,Modern apartment near metro station,EGP
|
| 21 |
+
20,Office,6530849,Cairo,Heliopolis,5,3,152,Office space in business district,EGP
|
| 22 |
+
21,Villa,7369905,Alexandria,Nasr City,4,1,370,Land plot suitable for building,EGP
|
| 23 |
+
22,Villa,9426259,Assiut,Heliopolis,2,2,63,Office space in business district,EGP
|
| 24 |
+
23,Office,9827183,Giza,Maadi,2,3,330,Office space in business district,EGP
|
| 25 |
+
24,Land,1476020,Assiut,Nasr City,1,1,118,Spacious villa with garden,EGP
|
| 26 |
+
25,Office,2583507,Mansoura,Zamalek,4,2,96,Land plot suitable for building,EGP
|
| 27 |
+
26,Apartment,6583752,Cairo,Heliopolis,5,2,375,Land plot suitable for building,EGP
|
| 28 |
+
27,Apartment,8750294,Mansoura,Heliopolis,1,3,324,Land plot suitable for building,EGP
|
| 29 |
+
28,Land,9962807,Giza,6th of October,4,2,295,Land plot suitable for building,EGP
|
| 30 |
+
29,Land,9833185,Assiut,Nasr City,1,3,222,Newly renovated flat with balcony,EGP
|
| 31 |
+
30,Apartment,1267702,Assiut,6th of October,4,2,349,Land plot suitable for building,EGP
|
| 32 |
+
31,Land,4978862,Alexandria,Zamalek,1,3,491,Newly renovated flat with balcony,EGP
|
| 33 |
+
32,Apartment,3311976,Alexandria,Maadi,3,3,87,Modern apartment near metro station,EGP
|
| 34 |
+
33,Villa,9800603,Cairo,6th of October,3,3,415,Land plot suitable for building,EGP
|
| 35 |
+
34,Apartment,5215539,Cairo,6th of October,1,2,132,Newly renovated flat with balcony,EGP
|
| 36 |
+
35,Apartment,2030323,Assiut,6th of October,1,2,456,Newly renovated flat with balcony,EGP
|
| 37 |
+
36,Land,1229937,Cairo,Zamalek,2,3,185,Newly renovated flat with balcony,EGP
|
| 38 |
+
37,Apartment,3416738,Giza,6th of October,5,3,62,Modern apartment near metro station,EGP
|
| 39 |
+
38,Office,9485850,Giza,Nasr City,1,2,344,Newly renovated flat with balcony,EGP
|
| 40 |
+
39,Land,1537491,Cairo,6th of October,4,3,181,Newly renovated flat with balcony,EGP
|
| 41 |
+
40,Villa,6844299,Giza,Zamalek,4,3,350,Modern apartment near metro station,EGP
|
| 42 |
+
41,Land,6778639,Mansoura,Heliopolis,1,2,92,Spacious villa with garden,EGP
|
| 43 |
+
42,Land,1219702,Assiut,Zamalek,3,3,186,Spacious villa with garden,EGP
|
| 44 |
+
43,Office,2663728,Cairo,Maadi,1,1,145,Modern apartment near metro station,EGP
|
| 45 |
+
44,Villa,6384841,Alexandria,Maadi,5,3,61,Spacious villa with garden,EGP
|
| 46 |
+
45,Apartment,6604749,Giza,Zamalek,1,3,395,Office space in business district,EGP
|
| 47 |
+
46,Apartment,7855255,Cairo,Zamalek,4,2,408,Spacious villa with garden,EGP
|
| 48 |
+
47,Office,3400030,Mansoura,6th of October,1,1,415,Newly renovated flat with balcony,EGP
|
| 49 |
+
48,Apartment,9106643,Giza,Heliopolis,2,2,163,Modern apartment near metro station,EGP
|
| 50 |
+
49,Office,5011389,Assiut,Zamalek,1,1,340,Office space in business district,EGP
|
| 51 |
+
50,Apartment,8926984,Giza,Maadi,2,2,253,Spacious villa with garden,EGP
|
| 52 |
+
51,Apartment,4522304,Alexandria,Zamalek,5,2,412,Spacious villa with garden,EGP
|
| 53 |
+
52,Apartment,920741,Mansoura,Nasr City,3,1,441,Office space in business district,EGP
|
| 54 |
+
53,Office,3498871,Giza,Zamalek,1,1,224,Modern apartment near metro station,EGP
|
| 55 |
+
54,Office,9623181,Mansoura,6th of October,2,3,244,Newly renovated flat with balcony,EGP
|
| 56 |
+
55,Office,6780958,Mansoura,6th of October,5,1,379,Modern apartment near metro station,EGP
|
| 57 |
+
56,Villa,5712670,Alexandria,Nasr City,3,1,152,Modern apartment near metro station,EGP
|
| 58 |
+
57,Office,7296704,Mansoura,Maadi,5,2,419,Modern apartment near metro station,EGP
|
| 59 |
+
58,Villa,4537148,Assiut,6th of October,2,2,466,Modern apartment near metro station,EGP
|
| 60 |
+
59,Office,7925711,Mansoura,Nasr City,4,2,263,Office space in business district,EGP
|
| 61 |
+
60,Villa,9641388,Assiut,Maadi,5,1,425,Office space in business district,EGP
|
| 62 |
+
61,Office,3787120,Cairo,6th of October,1,1,77,Newly renovated flat with balcony,EGP
|
| 63 |
+
62,Apartment,6520464,Alexandria,Maadi,1,2,171,Land plot suitable for building,EGP
|
| 64 |
+
63,Villa,2968895,Assiut,Zamalek,5,2,62,Land plot suitable for building,EGP
|
| 65 |
+
64,Office,565615,Mansoura,Heliopolis,5,1,326,Office space in business district,EGP
|
| 66 |
+
65,Villa,4316316,Cairo,Zamalek,4,1,431,Land plot suitable for building,EGP
|
| 67 |
+
66,Land,1074956,Giza,Nasr City,3,2,288,Land plot suitable for building,EGP
|
| 68 |
+
67,Office,5173951,Giza,Nasr City,5,2,153,Land plot suitable for building,EGP
|
| 69 |
+
68,Office,6948919,Mansoura,6th of October,3,2,285,Office space in business district,EGP
|
| 70 |
+
69,Villa,8087170,Alexandria,6th of October,4,3,402,Spacious villa with garden,EGP
|
| 71 |
+
70,Apartment,1674292,Mansoura,Maadi,3,1,241,Modern apartment near metro station,EGP
|
| 72 |
+
71,Land,6390437,Cairo,Heliopolis,5,2,428,Modern apartment near metro station,EGP
|
| 73 |
+
72,Apartment,1182110,Cairo,Heliopolis,3,2,314,Modern apartment near metro station,EGP
|
| 74 |
+
73,Villa,6171156,Mansoura,Nasr City,4,3,482,Office space in business district,EGP
|
| 75 |
+
74,Land,871243,Assiut,Heliopolis,5,2,443,Office space in business district,EGP
|
| 76 |
+
75,Villa,8166913,Alexandria,Zamalek,3,2,361,Newly renovated flat with balcony,EGP
|
| 77 |
+
76,Office,2199624,Giza,Heliopolis,5,2,282,Land plot suitable for building,EGP
|
| 78 |
+
77,Apartment,6150144,Cairo,Heliopolis,4,1,154,Modern apartment near metro station,EGP
|
| 79 |
+
78,Villa,637540,Cairo,Maadi,2,1,130,Modern apartment near metro station,EGP
|
| 80 |
+
79,Office,4112774,Cairo,Maadi,5,3,371,Newly renovated flat with balcony,EGP
|
| 81 |
+
80,Villa,6349989,Alexandria,6th of October,4,1,350,Spacious villa with garden,EGP
|
| 82 |
+
81,Villa,3727694,Cairo,Maadi,3,2,359,Office space in business district,EGP
|
| 83 |
+
82,Villa,9303544,Mansoura,Heliopolis,1,3,223,Spacious villa with garden,EGP
|
| 84 |
+
83,Apartment,4298773,Assiut,6th of October,1,3,298,Spacious villa with garden,EGP
|
| 85 |
+
84,Land,5441403,Giza,Zamalek,2,1,141,Newly renovated flat with balcony,EGP
|
| 86 |
+
85,Office,8542703,Cairo,Maadi,4,2,288,Land plot suitable for building,EGP
|
| 87 |
+
86,Office,9499409,Alexandria,Heliopolis,5,3,243,Land plot suitable for building,EGP
|
| 88 |
+
87,Villa,1922785,Mansoura,Heliopolis,3,2,224,Land plot suitable for building,EGP
|
| 89 |
+
88,Office,1632544,Giza,Heliopolis,2,2,63,Office space in business district,EGP
|
| 90 |
+
89,Land,8603707,Giza,Nasr City,4,3,164,Office space in business district,EGP
|
| 91 |
+
90,Office,1634231,Assiut,Heliopolis,2,3,458,Office space in business district,EGP
|
| 92 |
+
91,Office,9772813,Alexandria,Heliopolis,1,2,68,Spacious villa with garden,EGP
|
| 93 |
+
92,Land,4581829,Giza,Heliopolis,1,3,77,Office space in business district,EGP
|
| 94 |
+
93,Land,6094277,Alexandria,Maadi,2,1,170,Land plot suitable for building,EGP
|
| 95 |
+
94,Land,6969058,Alexandria,6th of October,4,3,251,Newly renovated flat with balcony,EGP
|
| 96 |
+
95,Apartment,4533014,Alexandria,Maadi,1,2,88,Spacious villa with garden,EGP
|
| 97 |
+
96,Office,2474991,Cairo,6th of October,2,1,371,Spacious villa with garden,EGP
|
| 98 |
+
97,Land,1622746,Assiut,Heliopolis,3,2,309,Spacious villa with garden,EGP
|
| 99 |
+
98,Office,6696372,Assiut,Zamalek,5,2,392,Spacious villa with garden,EGP
|
| 100 |
+
99,Land,1363176,Giza,Maadi,3,3,100,Office space in business district,EGP
|
| 101 |
+
100,Villa,9354939,Alexandria,Zamalek,5,1,89,Newly renovated flat with balcony,EGP
|
knowledge/knowledge_base.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Static knowledge base
|
| 2 |
+
class KnowledgeBase:
|
| 3 |
+
def __init__(self):
|
| 4 |
+
self.data = {"tip": "ุชุฃูุฏ ู
ู ู
ุนุงููุฉ ุงูุนูุงุฑ ูุจู ุงูุดุฑุงุก."}
|
| 5 |
+
|
| 6 |
+
def fetch(self, key):
|
| 7 |
+
return self.data.get(key, "ูุง ุชูุฌุฏ ู
ุนููู
ุงุช")
|
knowledge/retrieval.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Retrieval simulation
|
| 2 |
+
from knowledge.knowledge_base import KnowledgeBase
|
| 3 |
+
|
| 4 |
+
class Retriever:
|
| 5 |
+
def __init__(self):
|
| 6 |
+
self.kb = KnowledgeBase()
|
| 7 |
+
|
| 8 |
+
def retrieve(self, topic):
|
| 9 |
+
return self.kb.fetch(topic)
|
memory/conversation_history.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Stores chat history
|
| 2 |
+
class ConversationHistory:
|
| 3 |
+
def __init__(self):
|
| 4 |
+
self.history = []
|
| 5 |
+
|
| 6 |
+
def store(self, user_input):
|
| 7 |
+
self.history.append(user_input)
|
| 8 |
+
|
| 9 |
+
def get(self):
|
| 10 |
+
return self.history
|
memory/memory_processor.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Memory processor
|
| 2 |
+
class MemoryProcessor:
|
| 3 |
+
def summarize(self, history):
|
| 4 |
+
return "ู
ูุฎุต ุงูู
ุญุงุฏุซุฉ: " + " | ".join(history)
|
model/fallback_model.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Filled via update
|
model/yehia_interface.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 2 |
+
import torch
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Load model only once
|
| 6 |
+
model_name = "Navid-AI/Yehia-7B-preview"
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
+
model_name,
|
| 11 |
+
torch_dtype=torch.bfloat16,
|
| 12 |
+
device_map="auto"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
def query_yehia(user_message: str, history=None):
|
| 16 |
+
if history is None:
|
| 17 |
+
history = []
|
| 18 |
+
|
| 19 |
+
messages = [
|
| 20 |
+
{"role": "system", "content": "ุฃูุช ูุญููุ ูููู ู
ุจูุนุงุช ุนูุงุฑู ุฐูู ู
ุชุฎุตุต ูู ุชูุฏูู
ุงูู
ุดูุฑุฉ ููุนู
ูุงุก ุจุงููุบุฉ ุงูุนุฑุจูุฉ."},
|
| 21 |
+
*history,
|
| 22 |
+
{"role": "user", "content": user_message}
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 26 |
+
outputs = model.generate(**inputs, max_new_tokens=512)
|
| 27 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 28 |
+
|
| 29 |
+
return response
|
requirements(1).txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.25.0
|
| 2 |
+
transformers==4.40.0
|
| 3 |
+
torch>=2.1.0
|
| 4 |
+
python-dotenv
|
utils/arabic_nlp_helpers.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Filled via update
|
utils/text_processing.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Filled via update
|