faruqaziz commited on
Commit
a425de0
·
verified ·
1 Parent(s): 5490126

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -12,7 +12,7 @@ nltk.download('stopwords')
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):
@@ -31,7 +31,7 @@ jenis_kelamin = st.selectbox("Masukkan jenis kelamin Anda:", ["Laki-laki", "Pere
31
  gejala_id = st.text_area("Masukkan gejala Anda:")
32
 
33
  if st.button("Diagnosa"):
34
- if gejala_id and usia and jenis_kelamin:
35
  # Terjemahkan gejala dari Indonesia ke Inggris
36
  terjemahan = translator(gejala_id, max_length=100)
37
  gejala_en = terjemahan[0]["translation_text"]
@@ -40,7 +40,20 @@ if st.button("Diagnosa"):
40
 
41
  # Pesan untuk model
42
  pesan = [
43
- {"role": "system", "content": "You are a doctor who needs to diagnose a patient's illness. Provide one diagnosis that you believe is most confident."},
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  {"role": "user", "content": f"Based on your assessment, {gabungan}, what illness could it be?"}
45
  ]
46
 
@@ -54,18 +67,18 @@ if st.button("Diagnosa"):
54
  asisten_konten1 = get_assistant_content(response1)
55
 
56
  # Dapatkan respon dari pipe2 (model SumayyaAli)
57
- response2 = pipe2(pesan, num_return_sequences=1, truncation=True)
58
- asisten_konten2 = get_assistant_content(response2)
59
 
60
  # Gabungkan hasil dari pipe1 dan pipe2 untuk pertanyaan akhir
61
- 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."}]
62
 
63
  # Dapatkan hasil akhir diagnosis
64
- hasil_diagnosis = pipe1(pertanyaan_akhir)
65
- asisten_konten3 = get_assistant_content(hasil_diagnosis)
66
 
67
  # Terjemahkan hasil akhir ke bahasa Indonesia
68
- terjemahan_hasil = terjamah(asisten_konten3, max_length=100)
69
  diagnosa_terjemahan = terjemahan_hasil[0]["translation_text"]
70
 
71
  # Tampilkan hasil ke Streamlit
 
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):
 
31
  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"]
 
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, {gabungan}, what illness could it be?"}
58
  ]
59
 
 
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 = terjamah(asisten_konten1, max_length=100)
82
  diagnosa_terjemahan = terjemahan_hasil[0]["translation_text"]
83
 
84
  # Tampilkan hasil ke Streamlit