kadalicious22 commited on
Commit
cd52e60
·
verified ·
1 Parent(s): b6b859b

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +110 -0
  2. app.py +183 -0
  3. app.yaml +19 -0
  4. requirements.txt +2 -0
README.md ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dental AI Assistant - Asisten Kesehatan Gigi
2
+
3
+ Aplikasi chat AI yang dikhususkan untuk menjawab pertanyaan seputar kesehatan gigi dan mulut menggunakan Mistral AI API.
4
+
5
+ ## 🦷 Fitur
6
+
7
+ - **Chat AI Khusus Kedokteran Gigi**: Asisten cerdas yang fokus pada topik kesehatan gigi dan mulut
8
+ - **Filter Topik**: Hanya menjawab pertanyaan terkait kedokteran gigi
9
+ - **Bahasa Indonesia**: Respons dalam bahasa Indonesia (kecuali diminta dalam bahasa Inggris)
10
+ - **UI Gradio**: Interface yang modern dan mudah digunakan
11
+ - **Real-time Chat**: Percakapan real-time dengan contoh pertanyaan
12
+ - **Mobile Friendly**: Desain responsif untuk semua perangkat
13
+
14
+ ## 🚀 Cara Deploy ke Hugging Face Spaces (SUPER MUDAH)
15
+
16
+ ### 1. Upload Files ke GitHub
17
+
18
+ Upload semua file ini ke repository GitHub Anda:
19
+
20
+ ```
21
+ chatbotAI/
22
+ ├── app.py # Aplikasi Gradio utama
23
+ ├── requirements.txt # Dependencies Python
24
+ ├── app.yaml # Konfigurasi Hugging Face Spaces
25
+ └── README.md # Dokumentasi ini
26
+ ```
27
+
28
+ ### 2. Buat Hugging Face Space Baru
29
+
30
+ 1. Login ke [Hugging Face](https://huggingface.co/)
31
+ 2. Klik "Create new Space"
32
+ 3. Pilih:
33
+ - **Space Name**: `dental-ai-assistant` (atau nama lain)
34
+ - **SDK**: Gradio
35
+ - **Hardware**: CPU basic (free tier)
36
+ - **Visibility**: Public
37
+ - **Repository**: Pilih repository GitHub yang berisi file-file di atas
38
+
39
+ ### 3. Set API Key
40
+
41
+ 1. Di halaman Space, klik tab "Settings"
42
+ 2. Scroll ke "Repository secrets"
43
+ 3. Klik "New secret"
44
+ 4. Tambahkan:
45
+ - **Name**: `MISTRAL_API_KEY`
46
+ - **Value**: API Key dari Mistral AI
47
+
48
+ ### 4. Selesai! 🎉
49
+
50
+ Space akan otomatis build dan deploy. Tunggu beberapa menit dan aplikasi Anda akan online!
51
+
52
+ ## 🔧 Mendapatkan Mistral AI API Key (Gratis)
53
+
54
+ 1. Daftar di [Mistral AI](https://console.mistral.ai/)
55
+ 2. Verifikasi email Anda
56
+ 3. Dashboard → API Keys → Create new key
57
+ 4. Copy API key dan tambahkan ke environment variable Hugging Face Spaces
58
+
59
+ ## 📁 Struktur File (Sangat Sederhana)
60
+
61
+ ```
62
+ chatbotAI/
63
+ ├── app.py # Aplikasi Gradio dengan Mistral AI
64
+ ├── requirements.txt # Python dependencies (hanya 2 package)
65
+ ├── app.yaml # Konfigurasi Hugging Face Spaces
66
+ └── README.md # Dokumentasi
67
+ ```
68
+
69
+ ## 🎨 Teknologi yang Digunakan
70
+
71
+ - **Framework**: Gradio (built-in Hugging Face)
72
+ - **AI Model**: Mistral AI (mistral-tiny - free tier)
73
+ - **Backend**: Python
74
+ - **Deployment**: Hugging Face Spaces (auto-deploy)
75
+
76
+ ## ⚠️ Penting
77
+
78
+ - Aplikasi ini **bukan pengganti konsultasi dengan dokter gigi profesional**
79
+ - Hanya untuk informasi edukasi umum tentang kesehatan gigi
80
+ - Untuk masalah kesehatan gigi yang serius, selalu konsultasikan dengan dokter gigi
81
+
82
+ ## 🔍 Cara Penggunaan
83
+
84
+ 1. Buka website yang sudah di-deploy
85
+ 2. Klik contoh pertanyaan atau ketik pertanyaan sendiri
86
+ 3. AI akan merespons dengan informasi yang relevan
87
+ 4. Gunakan tombol "Hapus Chat" untuk memulai percakapan baru
88
+
89
+ ## 🐞 Troubleshooting
90
+
91
+ ### Error: "MISTRAL_API_KEY not found"
92
+ Pastikan environment variable `MISTRAL_API_KEY` sudah di-set di Settings → Repository secrets.
93
+
94
+ ### Error: "Message cannot be empty"
95
+ Pastikan Anda mengirim pesan yang tidak kosong.
96
+
97
+ ### Loading lama
98
+ Mistral AI free tier memiliki rate limit. Tunggu beberapa saat dan coba lagi.
99
+
100
+ ## 📝 Keuntungan Menggunakan Gradio
101
+
102
+ ✅ **No Docker needed** - Hugging Face handle semuanya
103
+ ✅ **Auto-deploy** - Push code dan auto update
104
+ ✅ **Built-in UI** - Tidak perlu HTML/CSS manual
105
+ ✅ **Mobile responsive** - Otomatis responsif
106
+ ✅ **Easy maintenance** - Hanya 2 file utama
107
+
108
+ ---
109
+
110
+ **Disclaimer**: Aplikasi ini hanya untuk informasi edukasi dan tidak menggantikan saran medis profesional.
app.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from mistralai.client import MistralClient
4
+ from mistralai.models.chat_completion import ChatMessage
5
+ import json
6
+
7
+ # Initialize Mistral client
8
+ # WARNING: API key hardcoded - NOT RECOMMENDED for production!
9
+ # Use environment variable for security
10
+ api_key = os.getenv("MISTRAL_API_KEY", "KjFqotgMkZgdJvWR5WCsOyvVS6wtjii6")
11
+ if not api_key:
12
+ print("Warning: MISTRAL_API_KEY not found in environment variables")
13
+
14
+ client = MistralClient(api_key=api_key)
15
+
16
+ # Dental-focused system prompt
17
+ DENTAL_SYSTEM_PROMPT = """You are a professional dental AI assistant specialized in dentistry and oral health.
18
+ Your role is to provide helpful, accurate information about dental topics including:
19
+ - Dental hygiene and preventive care
20
+ - Common dental procedures and treatments
21
+ - Oral health conditions and symptoms
22
+ - Dental anatomy and terminology
23
+ - Post-operative care instructions
24
+ - Dental emergency guidance
25
+
26
+ Important guidelines:
27
+ - Always emphasize that you're not a substitute for professional dental care
28
+ - Encourage users to consult with licensed dentists for specific medical advice
29
+ - Provide evidence-based information when possible
30
+ - Be clear about when immediate dental care is needed
31
+ - Use simple, understandable language for non-medical users
32
+ - Focus on educational and supportive information
33
+
34
+ Please respond in Indonesian language unless the user specifically asks for English."""
35
+
36
+ def is_dental_related(message):
37
+ """Simple check to determine if message is dental-related"""
38
+ dental_keywords = [
39
+ 'gigi', 'mulut', 'sakit gigi', 'berlubang', 'taring', 'gusi', 'karang gigi',
40
+ 'behel', 'kawat gigi', 'tambal gigi', 'cabut gigi', 'gigi tiruan', 'gigi palsu',
41
+ 'pembersihan', 'scaling', 'bleaching', 'veneer', 'mahkota gigi', 'implan',
42
+ 'odontologi', 'dokter gigi', 'klinik gigi', 'obat gigi', 'pasta gigi',
43
+ 'sikat gigi', 'benang gigi', 'kumur', 'mulut kering', 'bau mulut',
44
+ 'radang gusi', 'gingivitis', 'periodontitis', 'karies', 'plak',
45
+ 'tongue', 'lidah', 'saliva', 'liur', 'email gigi', 'dentin',
46
+ 'saraf gigi', 'akar gigi', 'gigi berlubang', 'gigi goyang', 'gigi tanggal',
47
+ 'gigi susu', 'gigi dewasa', 'gigi bungsu', 'wisdom tooth', 'orthodonti',
48
+ 'bracket', 'alat ortodonti', 'retainer', 'gigi rapat', 'gigi renggang',
49
+ 'gigi maju', 'gigi tonggos', 'gigi nongol', 'anestesi', 'bius',
50
+ 'x-ray gigi', 'radiologi', 'panoramic', 'cek up', 'kontrol', 'perawatan'
51
+ ]
52
+
53
+ message_lower = message.lower()
54
+ return any(keyword in message_lower for keyword in dental_keywords)
55
+
56
+ def dental_chat(message, history):
57
+ try:
58
+ if not message.strip():
59
+ return history + [[message, "Mohon masukkan pertanyaan yang valid."]]
60
+
61
+ # Check if message is dental-related
62
+ if not is_dental_related(message):
63
+ response = "Maaf, saya hanya bisa membantu dengan pertanyaan seputar kesehatan gigi dan mulut. Silakan ajukan pertanyaan tentang topik kedokteran gigi."
64
+ return history + [[message, response]]
65
+
66
+ # Create messages for Mistral API
67
+ messages = [
68
+ ChatMessage(role="system", content=DENTAL_SYSTEM_PROMPT),
69
+ ChatMessage(role="user", content=message)
70
+ ]
71
+
72
+ # Call Mistral API
73
+ chat_response = client.chat(
74
+ model="mistral-tiny", # Using free tier model
75
+ messages=messages,
76
+ max_tokens=500,
77
+ temperature=0.7
78
+ )
79
+
80
+ response = chat_response.choices[0].message.content
81
+ return history + [[message, response]]
82
+
83
+ except Exception as e:
84
+ print(f"Error in chat: {str(e)}")
85
+ return history + [[message, "Maaf, terjadi kesalahan. Silakan coba lagi."]]
86
+
87
+ # Custom CSS for dental theme
88
+ css = """
89
+ .main-container {
90
+ max-width: 800px !important;
91
+ margin: auto !important;
92
+ }
93
+ .gradio-container {
94
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
95
+ }
96
+ .message.user {
97
+ background: #4299e1 !important;
98
+ color: white !important;
99
+ }
100
+ .message.assistant {
101
+ background: #f7fafc !important;
102
+ border: 1px solid #e2e8f0 !important;
103
+ }
104
+ """
105
+
106
+ # Create Gradio interface
107
+ with gr.Blocks(theme=gr.themes.Soft(), title="Dental AI Assistant", css=css) as demo:
108
+ gr.Markdown("""
109
+ # 🦷 Dental AI Assistant
110
+ ### Asisten Kesehatan Gigi Berbasis AI
111
+
112
+ Tanyakan apa saja tentang kesehatan gigi dan mulut! Saya akan membantu dengan informasi edukatif.
113
+
114
+ ⚠️ **Penting:** Ini bukan pengganti konsultasi dengan dokter gigi profesional.
115
+ """)
116
+
117
+ chatbot = gr.Chatbot(
118
+ [],
119
+ height=500,
120
+ label="Chat dengan Dental AI",
121
+ show_copy_button=True,
122
+ bubble_full_width=False
123
+ )
124
+
125
+ msg = gr.Textbox(
126
+ label="Ketik pertanyaan tentang kesehatan gigi...",
127
+ placeholder="Contoh: Bagaimana cara menyikat gigi yang benar?",
128
+ lines=2
129
+ )
130
+
131
+ with gr.Row():
132
+ submit_btn = gr.Button("Kirim", variant="primary")
133
+ clear_btn = gr.Button("Hapus Chat", variant="secondary")
134
+
135
+ # Example questions
136
+ gr.Examples(
137
+ examples=[
138
+ "Bagaimana cara menyikat gigi yang benar?",
139
+ "Apa penyebab sakit gigi?",
140
+ "Kapan harus ke dokter gigi?",
141
+ "Apa itu scaling gigi?",
142
+ "Bagaimana cara mencegah gigi berlubang?"
143
+ ],
144
+ inputs=msg,
145
+ label="Contoh Pertanyaan:"
146
+ )
147
+
148
+ # Info section
149
+ with gr.Accordion("ℹ️ Informasi", open=False):
150
+ gr.Markdown("""
151
+ ### Yang Bisa Dilakukan Dental AI:
152
+ - Memberikan informasi tentang kesehatan gigi
153
+ - Menjelaskan prosedur kedokteran gigi
154
+ - Memberikan tips perawatan gigi
155
+ - Menjawab pertanyaan tentang masalah gigi umum
156
+
157
+ ### Batasan:
158
+ - Tidak bisa mendiagnosis kondisi medis spesifik
159
+ - Tidak menggantikan konsultasi dokter gigi
160
+ - Hanya untuk informasi edukasi umum
161
+ """)
162
+
163
+ # Event handlers
164
+ def user_input(user_message, history):
165
+ return "", history + [[user_message, None]]
166
+
167
+ def bot_response(history):
168
+ if history and history[-1][1] is None:
169
+ user_message = history[-1][0]
170
+ response = dental_chat(user_message, history[:-1])
171
+ return response
172
+ return history
173
+
174
+ msg.submit(user_input, [msg, chatbot], [msg, chatbot]).then(
175
+ bot_response, chatbot, chatbot
176
+ )
177
+ submit_btn.click(user_input, [msg, chatbot], [msg, chatbot]).then(
178
+ bot_response, chatbot, chatbot
179
+ )
180
+ clear_btn.click(lambda: None, None, chatbot, queue=False)
181
+
182
+ if __name__ == "__main__":
183
+ demo.launch(share=True)
app.yaml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ title: Dental AI Assistant
2
+ emoji: 🦷
3
+ colorFrom: blue
4
+ colorTo: teal
5
+ sdk: gradio
6
+ app_file: app.py
7
+ python_version: 3.9
8
+ license: mit
9
+ models: []
10
+ datasets: []
11
+ tags:
12
+ - chatbot
13
+ - healthcare
14
+ - dental
15
+ - ai-assistant
16
+ - mistralai
17
+ - indonesian
18
+ - kedokteran-gigi
19
+ - kesehatan-gigi
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio==4.19.2
2
+ mistralai==0.0.8