-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
133 lines (111 loc) · 5.01 KB
/
main.py
File metadata and controls
133 lines (111 loc) · 5.01 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#main.py
# Ayşenur Arslan - 16.04.2025
import argparse
import os
import sys
from PIL import Image
import logging
from modules.translator import Translator
# Modülleri içeri aktar
from modules.image_processor import get_image_from_source, preprocess_image
from modules.object_detector import ObjectDetector
from modules.keyword_extractor import KeywordExtractor
from modules.web_searcher import WebSearcher
from modules.data_storage import DataStorage
# Loglama ayarları
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler("app.log"),
logging.StreamHandler(sys.stdout)
]
)
logger = logging.getLogger(__name__)
def main():
# Argüman ayrıştırıcıyı ayarla
parser = argparse.ArgumentParser(description="Görüntü Analizi ve Sohbet Uygulaması")
parser.add_argument("--source", "-s", help="Görüntü URL'si veya dosya yolu (isteğe bağlı)")
args = parser.parse_args()
# Özel eğitilmiş modeli kullan
model_path = "D:\Masaüstü\goruntu_analizi_sohbet_uygulamasi\models\best.pt" # Modelinizin tam yolu
# Nesneleri başlat - özel model kullanımı için parametreleri geçir
object_detector = ObjectDetector(
model_path=model_path,
custom_model=True,
confidence_threshold=0.3,
ensemble=True, # Ensemble (birleştirme) modelini etkinleştir
optimize=True # Model optimizasyonunu etkinleşti
)
keyword_extractor = KeywordExtractor()
translator = Translator() # Çeviri nesnesi
web_searcher = WebSearcher()
data_storage = DataStorage()
print("=" * 50)
print("Görüntü Analizi ve Sohbet Uygulaması")
print("=" * 50)
# Komut satırı argümanı yoksa kullanıcıdan al
source = args.source
if not source:
source = input("Görüntü URL'si veya dosya yolu girin: ")
# Ana uygulama döngüsü
while True:
try:
# Görüntüyü al
print(f"\nGörüntü yükleniyor: {source}")
image = get_image_from_source(source)
processed_image = preprocess_image(image)
# Nesne tespiti
print("Görüntü analiz ediliyor...")
object_name, marked_image = object_detector.detect_objects(processed_image)
if not object_name:
print("Görüntüde tanımlanabilir bir nesne bulunamadı! Lütfen başka bir görüntü deneyin.")
source = input("\nYeni bir görüntü URL'si veya dosya yolu girin: ")
continue
# İngilizce nesne adını Türkçe'ye çevir
tr_object_name = translator.translate(object_name)
print(f"\n✓ Tespit edilen nesne: {object_name} (Türkçesi: {tr_object_name})")
# İsteğe bağlı: işaretlenmiş görüntüyü kaydet
marked_image.save("detected_object.jpg")
print("(İşaretlenmiş görüntü 'detected_object.jpg' olarak kaydedildi)")
# Anahtar kelime üretme
keywords = keyword_extractor.generate_keywords(tr_object_name, is_turkish=True)
print(f"✓ Anahtar kelimeler: {', '.join(keywords)}")
# Web'de arama
print("\nWeb'de bilgi aranıyor...")
search_results = web_searcher.search_web(tr_object_name, keywords, lang="tr")
if not search_results:
print("Web'de arama sonucu bulunamadı!")
source = input("\nYeni bir görüntü URL'si veya dosya yolu girin (çıkmak için 'q'): ")
if source.lower() == 'q':
break
continue
# İçerik çıkarma - object_name ve keywords parametrelerini geçirerek zenginleştir
content = web_searcher.extract_content(search_results, tr_object_name)
# Sonuçları göster
print("\n" + "=" * 50)
print(f" '{object_name}' HAKKINDA BİLGİLER ")
print("=" * 50)
print(content)
print("=" * 50)
# Veri saklama
data_storage.save_data(object_name, keywords, content)
print("✓ Sonuçlar başarıyla kaydedildi!")
# Yeni görüntü için sorgu
source = input("\nYeni bir görüntü URL'si veya dosya yolu girin (çıkmak için 'q'): ")
if source.lower() == 'q':
break
except Exception as e:
logger.error(f"Program hatası: {e}")
print(f"\nBir hata oluştu: {e}")
retry = input("Tekrar denemek için 'r', yeni bir görüntü için URL/dosya yolu girin, çıkmak için 'q': ")
if retry.lower() == 'q':
break
elif retry.lower() == 'r':
# Aynı kaynakla tekrar dene
continue
else:
# Yeni kaynak
source = retry
if __name__ == "__main__":
main()