faruqaziz commited on
Commit
e7c5b52
·
verified ·
1 Parent(s): 9c8d9f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -50
app.py CHANGED
@@ -2,28 +2,14 @@ import streamlit as st
2
  from transformers import pipeline
3
  import nltk
4
  from nltk.tokenize import word_tokenize
5
- from nltk.corpus import stopwords
6
-
7
- # Download data NLTK
8
- nltk.download('punkt')
9
- nltk.download('stopwords')
10
 
11
  # Buat objek terjemahan
12
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-id-en")
13
  terjemah = pipeline("translation", model="Helsinki-NLP/opus-mt-en-id")
14
- pipe1 = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")
15
- #pipe2 = pipeline("text-generation", model="SumayyaAli/tiny-llama-1.1b-chat-medical")
16
-
17
- # Pra-pemrosesan teks menggunakan NLTK
18
- def pra_pemrosesan_teks(teks):
19
- tokens = word_tokenize(teks)
20
- tokens = [token for token in tokens if token.isalnum()] # Menghapus kata bukan alfanumerik
21
- tokens = [token for token in tokens if token.lower() not in stopwords.words('indonesian')] # Menghapus stopword
22
- teks_diproses = " ".join(tokens)
23
- return teks_diproses
24
 
25
  # Antarmuka Streamlit
26
- st.title("Diagnosa Penyakit Berdasarkan Gejala")
27
 
28
  # Masukkan gejala, usia, dan jenis kelamin
29
  usia = st.number_input("Masukkan usia Anda:", min_value=0, max_value=120)
@@ -32,54 +18,37 @@ gejala_id = st.text_area("Masukkan gejala Anda:")
32
 
33
  if st.button("Diagnosa"):
34
  if gejala_id:
35
- # Terjemahkan gejala dari Indonesia ke Inggris
36
- terjemahan = translator(gejala_id, max_length=100)
37
- gejala_en = terjemahan[0]["translation_text"]
38
 
39
- informasi_pasien = f"I am {usia} years old, {jenis_kelamin}. And my current symptoms are {gejala_en}"
40
-
41
- # Pesan untuk model
42
  pesan = [
43
  {"role": "system",
44
- "content": """
45
- You are a doctor diagnosing patients based on symptoms.
46
 
47
  Example 1:
48
- Patient symptoms: High fever, headache, nausea
49
- Diagnosis: Dengue fever
50
 
51
  Example 2:
52
- Patient symptoms: Shortness of breath, chest pain, cough with phlegm
53
- Diagnosis: Pneumonia.
54
-
55
-
56
  """},
57
- {"role": "user", "content": f"Based on your assessment, {informasi_pasien}, what illness could it be?"}
58
  ]
59
 
60
  # Fungsi untuk mendapatkan konten dari role 'assistant'
61
  def get_assistant_content(response):
62
- generated_text = response [0]['generated_text']
63
- return generated_text
64
-
65
- # Dapatkan respon dari pipe1 (model TinyLlama)
66
- response1 = pipe1(pesan, num_return_sequences=1, truncation=True)
67
- asisten_konten1 = get_assistant_content(response1)
68
-
69
- # Dapatkan respon dari pipe2 (model SumayyaAli)
70
- #response2 = pipe2(pesan, num_return_sequences=1, truncation=True)
71
- #asisten_konten2 = get_assistant_content(response2)
72
-
73
- # Gabungkan hasil dari pipe1 dan pipe2 untuk pertanyaan akhir
74
- #pertanyaan_akhir = [{'role': 'user', 'content': f"{asisten_konten1}. {asisten_konten2}. Based on these two sentences, what is your final conclusion of my current symptom? Please provide a brief answer with one diagnosis."}]
75
 
76
- # Dapatkan hasil akhir diagnosis
77
- #hasil_diagnosis = pipe1(pertanyaan_akhir)
78
- #asisten_konten3 = get_assistant_content(hasil_diagnosis)
79
 
80
- # Terjemahkan hasil akhir ke bahasa Indonesia
81
- terjemahan_hasil = terjemah(asisten_konten1, max_length=100)
82
- diagnosa_terjemahan = terjemahan_hasil[0]["translation_text"]
83
 
84
  # Tampilkan hasil ke Streamlit
85
  st.subheader("Hasil Diagnosis:")
 
2
  from transformers import pipeline
3
  import nltk
4
  from nltk.tokenize import word_tokenize
 
 
 
 
 
5
 
6
  # Buat objek terjemahan
7
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-id-en")
8
  terjemah = pipeline("translation", model="Helsinki-NLP/opus-mt-en-id")
9
+ pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")
 
 
 
 
 
 
 
 
 
10
 
11
  # Antarmuka Streamlit
12
+ st.title("Diagnosa Berdasarkan Gejala Kehamilan")
13
 
14
  # Masukkan gejala, usia, dan jenis kelamin
15
  usia = st.number_input("Masukkan usia Anda:", min_value=0, max_value=120)
 
18
 
19
  if st.button("Diagnosa"):
20
  if gejala_id:
21
+ # Terjemahkan gejala dari Bahasa Indonesia ke Bahasa Inggris
22
+ gejala_en = translator(gejala_id, max_length=100)[0]["translation_text"]
23
+ informasi_pasien = f"I am {usia} years old, {jenis_kelamin}. Current symptoms are: {gejala_en}"
24
 
25
+ # Contoh kasus kehamilan untuk diagnosis
 
 
26
  pesan = [
27
  {"role": "system",
28
+ "content": """
29
+ You are a doctor diagnosing pregnancy-related conditions based on symptoms.
30
 
31
  Example 1:
32
+ Patient symptoms: Missed period, nausea, tender breasts
33
+ Diagnosis: Possible pregnancy
34
 
35
  Example 2:
36
+ Patient symptoms: Severe abdominal pain, bleeding
37
+ Diagnosis: Possible miscarriage or ectopic pregnancy.
 
 
38
  """},
39
+ {"role": "user", "content": f"Based on your assessment, {informasi_pasien}, what is your diagnosis?"}
40
  ]
41
 
42
  # Fungsi untuk mendapatkan konten dari role 'assistant'
43
  def get_assistant_content(response):
44
+ return response[0]['generated_text']
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
+ # Dapatkan respon dari pipe
47
+ response = pipe(pesan, num_return_sequences=1, truncation=True)
48
+ diagnosis = get_assistant_content(response)
49
 
50
+ # Terjemahkan hasil ke Bahasa Indonesia
51
+ diagnosa_terjemahan = terjemah(diagnosis, max_length=100)[0]["translation_text"]
 
52
 
53
  # Tampilkan hasil ke Streamlit
54
  st.subheader("Hasil Diagnosis:")