Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,15 @@
|
|
1 |
-
|
|
|
|
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
-
# Load
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
# Fungsi Chatbot
|
13 |
-
def chatbot_respon(user_input):
|
14 |
-
# Predefined responses based on intent
|
15 |
-
predefined_responses = {
|
16 |
-
"halo": "Hai juga! Ada yang bisa aku bantu?",
|
17 |
-
"apa kabar": "Aku baik, bagaimana dengan kamu?",
|
18 |
-
"siapa namamu": "Aku adalah IndoBot AI, teman bicaramu.",
|
19 |
-
"ceritakan lelucon": "Kenapa ayam menyeberang jalan? Untuk ke sisi lain!"
|
20 |
-
}
|
21 |
-
# Cari respons di predefined
|
22 |
-
for key, response in predefined_responses.items():
|
23 |
-
if key in user_input.lower():
|
24 |
-
return response
|
25 |
-
|
26 |
-
# Jika tidak ada di predefined, gunakan model
|
27 |
-
prediction = classifier(user_input)[0]
|
28 |
-
label = prediction['label']
|
29 |
-
confidence = prediction['score']
|
30 |
-
|
31 |
-
if confidence > 0.7: # Threshold confidence
|
32 |
-
if label == "LABEL_0":
|
33 |
-
return "Aku tidak yakin dengan pertanyaanmu, bisakah kamu menjelaskannya lebih lanjut?"
|
34 |
-
elif label == "LABEL_1":
|
35 |
-
return "Tentu! Aku bisa membantu menjelaskan topik ini lebih jauh."
|
36 |
-
|
37 |
-
return "Maaf, aku tidak mengerti pertanyaanmu."
|
38 |
-
|
39 |
-
# Gradio Interface
|
40 |
-
interface = gr.Interface(
|
41 |
-
fn=chatbot_respon,
|
42 |
-
inputs=gr.Textbox(lines=2, placeholder="Tanyakan sesuatu..."),
|
43 |
-
outputs="text",
|
44 |
-
title="IndoBot AI - Lebih Pintar",
|
45 |
-
description="IndoBot AI adalah chatbot berbasis bahasa Indonesia dengan pemahaman lebih mendalam. Tanyakan sesuatu!"
|
46 |
-
)
|
47 |
-
|
48 |
-
if __name__ == "__main__":
|
49 |
-
interface.launch()
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from sklearn.feature_extraction.text import CountVectorizer
|
3 |
+
from sklearn.naive_bayes import MultinomialNB
|
4 |
import gradio as gr
|
5 |
+
import csv
|
6 |
|
7 |
+
# Load Dataset
|
8 |
+
try:
|
9 |
+
df = pd.read_csv("dataset.csv")
|
10 |
+
except FileNotFoundError:
|
11 |
+
data = {"pertanyaan": [], "jawaban": []}
|
12 |
+
df = pd.DataFrame(data)
|
13 |
|
14 |
+
# Preprocessing Data
|
15 |
+
vectorizer = CountVectorize
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|