Spaces:
Sleeping
Sleeping
import os | |
from threading import Thread | |
from typing import Iterator | |
import re | |
import gradio as gr | |
import spaces | |
import torch | |
from transformers import AutoModelForCausalLM, Qwen2TokenizerFast, TextIteratorStreamer | |
# based on gemma demo code | |
DESCRIPTION = """\ | |
# SeaLLMs Med | |
SeaLLMs Med is a medical version of SeaLLMs | |
""" | |
MAX_MAX_NEW_TOKENS = 2048 | |
DEFAULT_MAX_NEW_TOKENS = 1024 | |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096")) | |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") | |
#model_id = "SeaLLMs/med-seallm3-7b-sftv2-department-recommend" | |
model_id = "SeaLLMs/debug_6" | |
tokenizer = Qwen2TokenizerFast.from_pretrained(model_id) | |
model = AutoModelForCausalLM.from_pretrained( | |
model_id, | |
device_map="auto", | |
torch_dtype=torch.bfloat16, | |
) | |
model.config.sliding_window = 4096 | |
model.eval() | |
system_prompt = "You are a helpful assistant." | |
mergeddepartment2hospital_eka = {'Akupunktur': [('EKA Hospital Bekasi', 'Akupuntur Medik'), ('EKA Hospital Pekanbaru', 'Akupuntur Medik'), ('EKA Hospital BSD', 'Spesialis Akupunktur Medik')], 'Spesialis Anak': [('EKA Hospital Bekasi', 'Spesialis Anak'), ('EKA Hospital BSD', 'Spesialis Anak'), ('EKA Hospital Cibubur', 'Spesialis Anak'), ('EKA Hospital Permata Hijau', 'Spesialis Anak'), ('EKA Hospital Pekanbaru', 'Spesialis Anak'), ('EKA Hospital Family', 'Dokter Spesialis Anak'), ('EKA Hospital Grand Family', 'Dokter Spesialis Anak')], 'Tumbuh kembang anak': [('EKA Hospital Bekasi', 'Tumbuh Kembang Anak'), ('EKA Hospital Pekanbaru', 'Tumbuh Kembang Anak')], 'Bedah Anak': [('EKA Hospital Bekasi', 'Bedah Anak'), ('EKA Hospital Pekanbaru', 'Bedah Anak'), ('EKA Hospital BSD', 'Spesialis Bedah Anak'), ('EKA Hospital Cibubur', 'Spesialis Bedah Anak'), ('EKA Hospital Grand Family', 'Dokter Spesialis Bedah Anak')], 'Bedah Digestif': [('EKA Hospital Bekasi', 'Bedah Digestif'), ('EKA Hospital Pekanbaru', 'Bedah Digestif'), ('EKA Hospital BSD', 'Spesialis Bedah Digestif'), ('EKA Hospital Cibubur', 'Spesialis Bedah Digestif')], 'Bedah Mulut': [('EKA Hospital Bekasi', 'Bedah Mulut'), ('EKA Hospital Pekanbaru', 'Bedah Mulut'), ('EKA Hospital BSD', 'Spesialis Bedah Mulut'), ('EKA Hospital Cibubur', 'Spesialis Bedah Mulut'), ('EKA Hospital Grand Family', 'Spesialis Bedah Mulut Dan Maksilofasial')], 'Bedah Onkologi': [('EKA Hospital Bekasi', 'Bedah Onkologi'), ('EKA Hospital Pekanbaru', 'Bedah Onkologi'), ('EKA Hospital BSD', 'Spesialis Bedah Onkologi'), ('EKA Hospital Cibubur', 'Spesialis Bedah Onkologi')], 'Bedah Plastik': [('EKA Hospital Bekasi', 'Bedah Plastik'), ('EKA Hospital Pekanbaru', 'Bedah Plastik'), ('EKA Hospital BSD', 'Spesialis Bedah Plastik'), ('EKA Hospital Cibubur', 'Spesialis Bedah Plastik')], 'Bedah Saraf': [('EKA Hospital Bekasi', 'Bedah Saraf'), ('EKA Hospital Pekanbaru', 'Bedah Saraf'), ('EKA Hospital BSD', 'Spesialis Bedah Saraf'), ('EKA Hospital Cibubur', 'Spesialis Bedah Saraf')], 'Bedah Thoraks Kardiovaskular': [('EKA Hospital Bekasi', 'Bedah Thoraks Kardiovaskular'), ('EKA Hospital Pekanbaru', 'Bedah Thoraks Kardiovaskular'), ('EKA Hospital BSD', 'Spesialis Bedah Toraks, Kardiak dan Vaskular'), ('EKA Hospital Cibubur', 'Spesialis Bedah Toraks, Kardiak dan Vaskular')], 'Bedah Umum': [('EKA Hospital Bekasi', 'Bedah Umum'), ('EKA Hospital Permata Hijau', 'Bedah Umum'), ('EKA Hospital Pekanbaru', 'Bedah Umum'), ('EKA Hospital BSD', 'Spesialis Bedah Umum'), ('EKA Hospital Cibubur', 'Spesialis Bedah Umum'), ('EKA Hospital Family', 'Dokter Spesialis Bedah'), ('EKA Hospital Grand Family', 'Dokter Spesialis Bedah')], 'Bedah Vaskular': [('EKA Hospital Bekasi', 'Bedah Vaskular'), ('EKA Hospital Pekanbaru', 'Bedah Vaskular'), ('EKA Hospital BSD', 'Spesialis Bedah Vaskular'), ('EKA Hospital Cibubur', 'Spesialis Bedah Vaskular')], 'Farmakologi Klinis': [('EKA Hospital Bekasi', 'Farmakologi Klinis'), ('EKA Hospital Pekanbaru', 'Farmakologi Klinis')], 'Dokter Gigi': [('EKA Hospital Bekasi', 'Dokter Gigi'), ('EKA Hospital Permata Hijau', 'Dokter Gigi'), ('EKA Hospital Pekanbaru', 'Dokter Gigi'), ('EKA Hospital Family', 'Dokter Gigi'), ('EKA Hospital Grand Family', 'Dokter Gigi'), ('EKA Hospital BSD', 'Gigi Umum'), ('EKA Hospital Cibubur', 'Gigi Umum')], 'Gizi Klinik': [('EKA Hospital Bekasi', 'Gizi Klinik'), ('EKA Hospital Pekanbaru', 'Gizi Klinik'), ('EKA Hospital BSD', 'Spesialis Gizi Klinik'), ('EKA Hospital Cibubur', 'Spesialis Gizi Klinik'), ('EKA Hospital Family', 'Dokter Spesialis Gizi Klinik')], 'Jantung & Pembuluh Darah': [('EKA Hospital Bekasi', 'Jantung & Pembuluh Darah'), ('EKA Hospital Permata Hijau', 'Jantung & Pembuluh Darah'), ('EKA Hospital Pekanbaru', 'Jantung & Pembuluh Darah'), ('EKA Hospital BSD', 'Spesialis Jantung dan Pembuluh Darah'), ('EKA Hospital Cibubur', 'Spesialis Jantung dan Pembuluh Darah')], 'Jantung Anak': [('EKA Hospital Bekasi', 'Jantung Anak'), ('EKA Hospital Pekanbaru', 'Jantung Anak'), ('EKA Hospital BSD', 'Spesialis Jantung Anak')], 'Kebidanan & Kandungan': [('EKA Hospital Bekasi', 'Kebidanan & Kandungan'), ('EKA Hospital Pekanbaru', 'Kebidanan & Kandungan'), ('EKA Hospital Permata Hijau', 'Kandungan & Kebidanan'), ('EKA Hospital BSD', 'Spesialis Kebidanan dan Kandungan'), ('EKA Hospital Cibubur', 'Spesialis Kebidanan dan Kandungan'), ('Pusat Unggulan', 'Pusat Layanan Kebidanan & Kandungan'), ('EKA Hospital Family', 'Dokter Spesialis Kandungan'), ('EKA Hospital Grand Family', 'Dokter Spesialis Kandungan')], 'Kebidanan Onkologi': [('EKA Hospital Bekasi', 'Kebidanan Onkologi'), ('EKA Hospital Pekanbaru', 'Kebidanan Onkologi'), ('EKA Hospital BSD', 'Spesialis Ginekologi Onkologi'), ('EKA Hospital Cibubur', 'Spesialis Ginekologi Onkologi')], 'Kedokteran Fisik & Rehabilitasi': [('EKA Hospital Bekasi', 'Kedokteran Fisik & Rehabilitasi'), ('EKA Hospital Pekanbaru', 'Kedokteran Fisik & Rehabilitasi'), ('EKA Hospital BSD', 'Spesialis Kedokteran Fisik dan Rehabilitasi'), ('EKA Hospital Cibubur', 'Spesialis Kedokteran Fisik dan Rehabilitasi'), ('EKA Hospital Family', 'Dokter Spesialis Kedokteran Fisik Dan Rehabilitasi'), ('EKA Hospital Grand Family', 'Dokter Spesialis Kedokteran Fisik Dan Rehabilitasi')], 'Kedokteran Okupasi': [('EKA Hospital Bekasi', 'Kedokteran Okupasi'), ('EKA Hospital Pekanbaru', 'Kedokteran Okupasi')], 'Kedokteran Olahraga': [('EKA Hospital Bekasi', 'Kedokteran Olahraga'), ('EKA Hospital Pekanbaru', 'Kedokteran Olahraga'), ('EKA Hospital BSD', 'Spesialis Kedokteran Olahraga')], 'Kesehatan Gigi Anak': [('EKA Hospital Bekasi', 'Kesehatan Gigi Anak'), ('EKA Hospital Pekanbaru', 'Kesehatan Gigi Anak'), ('EKA Hospital BSD', 'Spesialis Kesehatan Gigi Anak'), ('EKA Hospital Cibubur', 'Spesialis Kesehatan Gigi Anak'), ('EKA Hospital Family', 'Dokter Spesialis Kesehatan Gigi Anak'), ('EKA Hospital Grand Family', 'Dokter Spesialis Kesehatan Gigi Anak')], 'Konservasi Gigi': [('EKA Hospital Bekasi', 'Konservasi Gigi'), ('EKA Hospital Permata Hijau', 'Konservasi Gigi'), ('EKA Hospital Pekanbaru', 'Konservasi Gigi'), ('EKA Hospital BSD', 'Spesialis Konservasi Gigi'), ('EKA Hospital Cibubur', 'Spesialis Konservasi Gigi'), ('EKA Hospital Grand Family', 'Dokter Spesialis Konservasi Gigi')], 'Kulit & Kelamin': [('EKA Hospital Bekasi', 'Kulit & Kelamin'), ('EKA Hospital Pekanbaru', 'Kulit & Kelamin'), ('EKA Hospital BSD', 'Spesialis Kulit dan Kelamin'), ('EKA Hospital Cibubur', 'Spesialis Kulit dan Kelamin'), ('EKA Hospital Permata Hijau', 'Dermatologi & Venereologi'), ('EKA Hospital Family', 'Dermatologi & Venerologi'), ('EKA Hospital Grand Family', 'Dermatologi & Venerologi')], 'Spesialis Mata': [('EKA Hospital Bekasi', 'Spesialis Mata'), ('EKA Hospital BSD', 'Spesialis Mata'), ('EKA Hospital Cibubur', 'Spesialis Mata'), ('EKA Hospital Pekanbaru', 'Spesialis Mata'), ('EKA Hospital Permata Hijau', 'Dokter Mata')], 'Mikrobiologi Klinik': [('EKA Hospital Bekasi', 'Mikrobiologi Klinik'), ('EKA Hospital Pekanbaru', 'Mikrobiologi Klinik'), ('EKA Hospital BSD', 'Spesialis Mikrobiologi Klinik'), ('EKA Hospital Cibubur', 'Spesialis Mikrobiologi Klinik')], 'Orthodonti': [('EKA Hospital Bekasi', 'Orthodonti'), ('EKA Hospital Pekanbaru', 'Orthodonti'), ('EKA Hospital BSD', 'Spesialis Ortodonsia'), ('EKA Hospital Cibubur', 'Spesialis Ortodonsia')], 'Orthopedi & Traumatologi': [('EKA Hospital Bekasi', 'Orthopedi & Traumatologi'), ('EKA Hospital Permata Hijau', 'Orthopedi & Traumatologi'), ('EKA Hospital Pekanbaru', 'Orthopedi & Traumatologi'), ('EKA Hospital Grand Family', 'Orthopedi & Traumatologi'), ('EKA Hospital BSD', 'Spesialis Orthopedi Traumatologi'), ('EKA Hospital Cibubur', 'Spesialis Orthopedi Traumatologi')], 'Orthopedi: Cedera Bahu & Tangan': [('EKA Hospital Bekasi', 'Orthopedi: Cedera Bahu & Tangan'), ('EKA Hospital Pekanbaru', 'Orthopedi: Cedera Bahu & Tangan'), ('EKA Hospital BSD', 'Spesialis Orthopedi Cedera Bahu dan Tangan')], 'Orthopedi: Pediatrik/Anak': [('EKA Hospital Bekasi', 'Orthopedi: Pediatrik/anak'), ('EKA Hospital Pekanbaru', 'Orthopedi: Pediatrik/anak'), ('EKA Hospital BSD', 'Spesialis Orthopedi Pediatrik/Anak'), ('EKA Hospital Cibubur', 'Spesialis Orthopedi Pediatrik/Anak')], 'Orthopedi: Sendi Lutut & Pinggul': [('EKA Hospital Bekasi', 'Orthopedi: Sendi Lutut & Pinggul'), ('EKA Hospital Pekanbaru', 'Orthopedi: Sendi Lutut & Pinggul'), ('EKA Hospital BSD', 'Spesialis Orthopedi: Sendi Lutut dan Pinggul'), ('EKA Hospital Cibubur', 'Spesialis Orthopedi: Sendi Lutut dan Pinggul')], 'Orthopedi: Tulang Belakang': [('EKA Hospital Bekasi', 'Orthopedi: Tulang Belakang'), ('EKA Hospital Pekanbaru', 'Orthopedi: Tulang Belakang'), ('EKA Hospital BSD', 'Spesialis Orthopedi Tulang Belakang'), ('EKA Hospital Cibubur', 'Spesialis Orthopedi Tulang Belakang')], 'Orthopedi: Kaki dan Pergelangan Kaki': [('EKA Hospital BSD', 'Spesialis Orthopedi: Kaki dan Pergelangan Kaki')], 'Spesialis Paru': [('EKA Hospital Bekasi', 'Spesialis Paru'), ('EKA Hospital Pekanbaru', 'Spesialis Paru'), ('EKA Hospital BSD', 'Spesialis Paru dan Pernapasan'), ('EKA Hospital Cibubur', 'Spesialis Paru dan Pernapasan'), ('EKA Hospital Permata Hijau', 'Paru & Pernapasan')], 'Patologi Anatomi': [('EKA Hospital Bekasi', 'Patologi Anatomi'), ('EKA Hospital Pekanbaru', 'Patologi Anatomi'), ('EKA Hospital BSD', 'Spesialis Patologi Anatomi'), ('EKA Hospital Cibubur', 'Spesialis Patologi Anatomi')], 'Patologi Klinik': [('EKA Hospital Bekasi', 'Patologi Klinik'), ('EKA Hospital Pekanbaru', 'Patologi Klinik'), ('EKA Hospital BSD', 'Spesialis Patologi Klinik'), ('EKA Hospital Cibubur', 'Spesialis Patologi Klinik')], 'Penyakit Dalam': [('EKA Hospital Bekasi', 'Penyakit Dalam'), ('EKA Hospital Permata Hijau', 'Penyakit Dalam'), ('EKA Hospital Pekanbaru', 'Penyakit Dalam'), ('EKA Hospital BSD', 'Spesialis Penyakit Dalam'), ('EKA Hospital Cibubur', 'Spesialis Penyakit Dalam'), ('EKA Hospital Family', 'Dokter Spesialis Penyakit Dalam'), ('EKA Hospital Grand Family', 'Dokter Spesialis Penyakit Dalam')], 'Penyakit Dalam: Hemato-Onkologi': [('EKA Hospital Bekasi', 'Penyakit Dalam: Hemato-onkologi'), ('EKA Hospital Pekanbaru', 'Penyakit Dalam: Hemato-onkologi')], 'Penyakit Dalam: Ginjal & Hipertensi': [('EKA Hospital Permata Hijau', 'Penyakit Dalam : Ginjal & Hipertensi')], 'Periodonti': [('EKA Hospital Bekasi', 'Periodonti'), ('EKA Hospital Pekanbaru', 'Periodonti')], 'Prostodonti': [('EKA Hospital Bekasi', 'Prostodonti'), ('EKA Hospital Pekanbaru', 'Prostodonti'), ('EKA Hospital BSD', 'Spesialis Prostodonsia'), ('EKA Hospital Cibubur', 'Spesialis Prostodonsia'), ('EKA Hospital Grand Family', 'Dokter Spesialis Prostodonsia')], 'Psikiatri': [('EKA Hospital Bekasi', 'Psikiatri'), ('EKA Hospital Pekanbaru', 'Psikiatri'), ('EKA Hospital BSD', 'Spesialis Psikiatri'), ('EKA Hospital Cibubur', 'Spesialis Psikiatri')], 'Psikolog Klinis': [('EKA Hospital Bekasi', 'Psikolog Klinis'), ('EKA Hospital BSD', 'Psikolog Klinis'), ('EKA Hospital Cibubur', 'Psikolog Klinis'), ('EKA Hospital Pekanbaru', 'Psikolog Klinis'), ('EKA Hospital Grand Family', 'Psikolog')], 'Spesialis Saraf': [('EKA Hospital Bekasi', 'Spesialis Saraf'), ('EKA Hospital BSD', 'Spesialis Saraf'), ('EKA Hospital Cibubur', 'Spesialis Saraf'), ('EKA Hospital Permata Hijau', 'Spesialis Saraf'), ('EKA Hospital Pekanbaru', 'Spesialis Saraf'), ('EKA Hospital Permata Hijau', 'Neurologi')], 'THT-KL': [('EKA Hospital Bekasi', 'THT-KL'), ('EKA Hospital Pekanbaru', 'THT-KL'), ('EKA Hospital BSD', 'Spesialis THT-KL'), ('EKA Hospital Cibubur', 'Spesialis THT-KL'), ('EKA Hospital Permata Hijau', 'THT')], 'Urologi': [('EKA Hospital Bekasi', 'Urologi'), ('EKA Hospital Permata Hijau', 'Urologi'), ('EKA Hospital Pekanbaru', 'Urologi'), ('Pusat Unggulan', 'Urology & Couple Clinic'), ('EKA Hospital BSD', 'Spesialis Urologi'), ('EKA Hospital Cibubur', 'Spesialis Urologi')], 'Dokter Umum': [('EKA Hospital BSD', 'Dokter Umum'), ('EKA Hospital Cibubur', 'Dokter Umum')], 'Laktasi': [('EKA Hospital Family', 'Dokter Laktasi'), ('EKA Hospital Grand Family', 'Dokter Laktasi')], 'Rehabilitasi Medik': [('EKA Hospital Permata Hijau', 'Rehabilitasi Medik')], 'Anestesi': [('EKA Hospital Bekasi', 'Anastesi'), ('EKA Hospital Pekanbaru', 'Anastesi'), ('EKA Hospital BSD', 'Spesialis Anestesi'), ('EKA Hospital Cibubur', 'Spesialis Anestesi')], 'Radiologi': [('EKA Hospital BSD', 'Spesialis Radiologi'), ('EKA Hospital Cibubur', 'Spesialis Radiologi'), ('EKA Hospital Family', 'Dokter Spesialis Radiologi'), ('EKA Hospital Grand Family', 'Dokter Spesialis Radiologi')], 'Dokter Lainnya': [('EKA Hospital Family', 'Dokter Lainnya')], 'Pusat Layanan Kesehatan Anak Terpadu': [('Pusat Unggulan', 'Pusat Layanan Kesehatan Anak Terpadu')], 'Eka Tjipta Widjaja Cancer Center': [('Pusat Unggulan', 'ETWCC: Eka Tjipta Widjaja Cancer Center')], 'Gatam Institute: Pusat Ortopedi & Tulang Belakang': [('Pusat Unggulan', 'Gatam Institute: Pusat Ortopedi & Tulang Belakang')], 'Mycardia: Pusat Layanan Jantung dan Pembuluh Darah': [('Pusat Unggulan', 'MYcardia: Pusat Layanan Jantung dan Pembuluh Darah')], 'Pusat Neonatal Intensive Care (NICU)': [('Pusat Unggulan', 'Pusat Neonatal Intensive Care (NICU)')], 'Diabetes Connection Care: Pusat Diabetes Terintegrasi': [('Pusat Unggulan', 'Diabetes Connection Care: Pusat Diabetes Terintegrasi')], 'Divine: Digestive Intervention & Endoscopy Center': [('Pusat Unggulan', 'DIVINE: Digestive Intervention & Endoscopy Center')], 'Spesialis kedokteran penerbangan': [('EKA Hospital BSD', 'Spesialis Kedokteran Penerbangan')], 'Anak: hemato-onkologi': [('EKA Hospital Bekasi', 'Anak: Hemato-onkologi'), ('EKA Hospital Pekanbaru', 'Anak: Hemato-onkologi')]} | |
def extract_list(text, type): | |
pattern = rf'<{type}>(.*?)</{type}>' | |
matches = re.findall(pattern, text) | |
matches = [x.strip() for x in matches] | |
return matches | |
def check_department_eka_simple(text): | |
departments = extract_list(text, 'd') | |
good_department = {x.lower():1 for x in mergeddepartment2hospital_eka.keys()} | |
if departments: | |
good = True | |
for item in departments: | |
if item.lower() in good_department: | |
continue | |
else: | |
good = False | |
break | |
else: | |
good = False | |
return good, departments | |
def generate( | |
message: str, | |
chat_history: list[tuple[str, str]], | |
max_new_tokens: int = 1024, | |
temperature: float = 0.6, | |
top_p: float = 0.9, | |
top_k: int = 50, | |
repetition_penalty: float = 1.2, | |
) -> Iterator[str]: | |
# conversation = [{"role": "system", "content": system_prompt}] | |
conversation = [] | |
department_text = f"{list(mergeddepartment2hospital_eka.keys())}" | |
message = user_text = f'''Department: | |
{department_text} | |
Question: | |
{message}''' | |
#Please reply to the above question and add a disclaimer statement "Informasi yang kami berikan tidak sesuai untuk, dan tidak boleh dianggap sebagai, bentuk layanan diagnosis apapun. Anda tidak boleh mengandalkan informasi yang diberikan oleh layanan teknis kami untuk mendiagnosis atau mengobati penyakit." in your response. | |
for user, assistant in chat_history: | |
conversation.extend( | |
[ | |
{"role": "user", "content": user}, | |
{"role": "assistant", "content": assistant}, | |
] | |
) | |
conversation.append({"role": "user", "content": message}) | |
input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt") | |
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH: | |
input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:] | |
gr.Warning(f"Trimmed input from conversation as it was longer than {MAX_INPUT_TOKEN_LENGTH} tokens.") | |
input_ids = input_ids.to(model.device) | |
streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True) | |
generate_kwargs = dict( | |
{"input_ids": input_ids}, | |
streamer=streamer, | |
max_new_tokens=max_new_tokens, | |
do_sample=True, | |
top_p=top_p, | |
top_k=top_k, | |
temperature=temperature, | |
num_beams=1, | |
repetition_penalty=repetition_penalty, | |
eos_token_id=tokenizer.eos_token_id, | |
) | |
t = Thread(target=model.generate, kwargs=generate_kwargs) | |
t.start() | |
outputs = [] | |
department_all = '' | |
d_flag = False | |
for text in streamer: | |
if (not d_flag) and "<d>" in text and "</d>" in text: | |
department_all += department | |
elif (not d_flag) and "<d>" in text: | |
d_flag = True | |
department = text | |
elif d_flag and (not "</d>" in text): | |
department += text | |
elif d_flag and "</d>" in text: | |
department += text | |
department_all += department | |
d_flag = False | |
outputs.append(text.replace("<d>", "").replace("</d>", "")) | |
yield "".join(outputs) | |
good, departments = check_department_eka_simple(department_all) | |
if good: | |
recommendation_text = '\nDepartemen yang direkomendasikan di atas dapat ditemukan di beberapa cabang EKA Hospital:\n' | |
for i_d, item in enumerate(departments): | |
hospital = mergeddepartment2hospital_eka[item] | |
hospital = [f" * {x[1]}, {x[0]}" for x in hospital] | |
item_text = f"{i_d+1}. {item}:\n" | |
hospital_text = "\n".join(hospital) | |
recommendation_text += item_text + hospital_text + "\n" | |
yield "".join(outputs) + recommendation_text | |
chat_interface = gr.ChatInterface( | |
fn=generate, | |
additional_inputs=[], | |
stop_btn=None, | |
examples=[ | |
["prosedur ASO ditawarkan di Eka cabang mana?"], | |
["Di bibir atas saya muncul bintik-bintik berwarna putih bintiknya kecil-kecil dan rasanya gatal. Kira-kira kenapa ya dok? apakah saya alergi makanan dok? soalnya saya td abis makan buah mangga mentah"] | |
], | |
cache_examples=False, | |
) | |
with gr.Blocks(css="style.css", fill_height=True) as demo: | |
gr.Markdown(DESCRIPTION) | |
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button") | |
chat_interface.render() | |
if __name__ == "__main__": | |
demo.queue(max_size=20).launch() |