nurqoneah commited on
Commit
d9f072c
Β·
verified Β·
1 Parent(s): 6f1c7f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -26
app.py CHANGED
@@ -18,7 +18,7 @@ APP_TITLE = "πŸ’Š Asisten Kesehatan Feminacare"
18
  INITIAL_MESSAGE = """Halo! πŸ‘‹ Saya adalah asisten kesehatan feminacare yang siap membantu Anda dengan informasi seputar kesehatan wanita.
19
  Silakan ajukan pertanyaan apa saja dan saya akan membantu Anda dengan informasi yang akurat."""
20
 
21
- MODEL_NAME = "SeaLLMs/SeaLLMs-v3-7B-Chat"
22
  EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
23
  TOP_K_DOCS = 5
24
 
@@ -34,34 +34,43 @@ def initialize_models():
34
 
35
  def create_llm():
36
  """Initialize the language model with auto device mapping"""
37
- model = AutoModelForCausalLM.from_pretrained(
38
- MODEL_NAME,
39
- device_map="auto",
40
- trust_remote_code=True
41
- )
42
- tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
43
 
44
- # Get terminators for the model
45
- terminators = [tokenizer.eos_token_id]
46
- if hasattr(tokenizer, 'convert_tokens_to_ids'):
47
- try:
48
- terminators.append(tokenizer.convert_tokens_to_ids("<|eot_id|>"))
49
- except:
50
- pass
51
 
52
- text_generation_pipeline = pipeline(
53
- model=model,
54
- tokenizer=tokenizer,
55
- task="text-generation",
56
- temperature=0.2,
57
- do_sample=True,
58
- repetition_penalty=1.1,
59
- return_full_text=False,
60
- max_new_tokens=200,
61
- eos_token_id=terminators,
62
- )
63
 
64
- return HuggingFacePipeline(pipeline=text_generation_pipeline)
 
 
 
 
 
 
 
 
 
65
 
66
  PROMPT_TEMPLATE = """
67
  Anda adalah asisten kesehatan profesional dengan nama Feminacare.
 
18
  INITIAL_MESSAGE = """Halo! πŸ‘‹ Saya adalah asisten kesehatan feminacare yang siap membantu Anda dengan informasi seputar kesehatan wanita.
19
  Silakan ajukan pertanyaan apa saja dan saya akan membantu Anda dengan informasi yang akurat."""
20
 
21
+ MODEL_NAME = "SeaLLMs/SeaLLM-13B-Chat"
22
  EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
23
  TOP_K_DOCS = 5
24
 
 
34
 
35
  def create_llm():
36
  """Initialize the language model with auto device mapping"""
37
+ # model = AutoModelForCausalLM.from_pretrained(
38
+ # MODEL_NAME,
39
+ # device_map="auto",
40
+ # trust_remote_code=True
41
+ # )
42
+ # tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
43
 
44
+ # # Get terminators for the model
45
+ # terminators = [tokenizer.eos_token_id]
46
+ # if hasattr(tokenizer, 'convert_tokens_to_ids'):
47
+ # try:
48
+ # terminators.append(tokenizer.convert_tokens_to_ids("<|eot_id|>"))
49
+ # except:
50
+ # pass
51
 
52
+ # text_generation_pipeline = pipeline(
53
+ # model=model,
54
+ # tokenizer=tokenizer,
55
+ # task="text-generation",
56
+ # temperature=0.2,
57
+ # do_sample=True,
58
+ # repetition_penalty=1.1,
59
+ # return_full_text=False,
60
+ # max_new_tokens=200,
61
+ # eos_token_id=terminators,
62
+ # )
63
 
64
+ # return HuggingFacePipeline(pipeline=text_generation_pipeline)
65
+ return HuggingFaceHub(
66
+ repo_id=MODEL_NAME,
67
+ model_kwargs={
68
+ "temperature": 0.7, # Balanced between creativity and accuracy
69
+ "max_new_tokens": 1024,
70
+ "top_p": 0.9,
71
+ "frequency_penalty": 0.5
72
+ }
73
+ )
74
 
75
  PROMPT_TEMPLATE = """
76
  Anda adalah asisten kesehatan profesional dengan nama Feminacare.