Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,15 +51,13 @@ def generate_answer(prompt):
|
|
| 51 |
def clean(text):
|
| 52 |
text = re.sub(r"[^a-zA-ZğüşöçıİĞÜŞÖÇ0-9.,:%()\-\s]", "", text)
|
| 53 |
text = re.sub(r"\s+", " ", text).strip()
|
| 54 |
-
# yalnızca ilk cümleyi al
|
| 55 |
if "." in text:
|
| 56 |
text = text.split(".")[0].strip() + "."
|
| 57 |
-
# gereksiz uzamayı kısalt
|
| 58 |
if len(text) > 200:
|
| 59 |
text = text[:200].rsplit(" ", 1)[0] + "..."
|
| 60 |
return text
|
| 61 |
|
| 62 |
-
# -----------------
|
| 63 |
PROMPT_TMPL = (
|
| 64 |
"Kredi kartı dolandırıcılığı alanında uzmansın. "
|
| 65 |
"Soruyu tekrarlama. Türkçe, kısa ve açık bir yanıt ver. "
|
|
@@ -88,30 +86,24 @@ def chat(question):
|
|
| 88 |
return ans
|
| 89 |
|
| 90 |
# ----------------- Arayüz -----------------
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
"sorularınıza kısa ve net Türkçe yanıtlar verir. "
|
| 96 |
-
"Yapay zekâ modeli bağlama göre cevap üretir, soru tekrarlamaz."
|
| 97 |
-
)
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
| 102 |
clear = gr.Button("Temizle")
|
|
|
|
| 103 |
|
| 104 |
state = gr.State([])
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
hist = (hist or []) + [(msg, ans)]
|
| 109 |
-
return hist, ""
|
| 110 |
-
|
| 111 |
-
send.click(on_send, inputs=[user_inp, state], outputs=[chatbox, user_inp]).then(
|
| 112 |
-
lambda h: h, chatbox, state
|
| 113 |
)
|
| 114 |
-
clear.click(lambda: ([], ""),
|
| 115 |
|
| 116 |
if __name__ == "__main__":
|
| 117 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
@@ -123,4 +115,5 @@ if __name__ == "__main__":
|
|
| 123 |
|
| 124 |
|
| 125 |
|
|
|
|
| 126 |
|
|
|
|
| 51 |
def clean(text):
|
| 52 |
text = re.sub(r"[^a-zA-ZğüşöçıİĞÜŞÖÇ0-9.,:%()\-\s]", "", text)
|
| 53 |
text = re.sub(r"\s+", " ", text).strip()
|
|
|
|
| 54 |
if "." in text:
|
| 55 |
text = text.split(".")[0].strip() + "."
|
|
|
|
| 56 |
if len(text) > 200:
|
| 57 |
text = text[:200].rsplit(" ", 1)[0] + "..."
|
| 58 |
return text
|
| 59 |
|
| 60 |
+
# ----------------- Chat Mantığı -----------------
|
| 61 |
PROMPT_TMPL = (
|
| 62 |
"Kredi kartı dolandırıcılığı alanında uzmansın. "
|
| 63 |
"Soruyu tekrarlama. Türkçe, kısa ve açık bir yanıt ver. "
|
|
|
|
| 86 |
return ans
|
| 87 |
|
| 88 |
# ----------------- Arayüz -----------------
|
| 89 |
+
def respond(message, history):
|
| 90 |
+
response = chat(message)
|
| 91 |
+
history = history + [(message, response)]
|
| 92 |
+
return history, ""
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
with gr.Blocks(title="Kredi Kartı Dolandırıcılık Chatbotu") as demo:
|
| 95 |
+
gr.Markdown("## 💳 Gelişmiş Kredi Kartı Dolandırıcılık Analizi Chatbotu")
|
| 96 |
+
chatbot = gr.Chatbot(height=400, label="Chatbot")
|
| 97 |
+
msg = gr.Textbox(label="Soru", placeholder="Örneğin: Class sütunu 1 olunca ne olur?")
|
| 98 |
clear = gr.Button("Temizle")
|
| 99 |
+
send = gr.Button("Gönder", variant="primary")
|
| 100 |
|
| 101 |
state = gr.State([])
|
| 102 |
|
| 103 |
+
send.click(respond, inputs=[msg, state], outputs=[chatbot, msg]).then(
|
| 104 |
+
lambda h: h, chatbot, state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
)
|
| 106 |
+
clear.click(lambda: ([], ""), None, [chatbot, msg])
|
| 107 |
|
| 108 |
if __name__ == "__main__":
|
| 109 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
+
|
| 119 |
|