sounar commited on
Commit
9998c92
·
verified ·
1 Parent(s): 2738939

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -11,37 +11,38 @@ model_name = "ContactDoctor/Bio-Medical-MultiModal-Llama-3-8B-V1"
11
 
12
  # Load the Hugging Face model and tokenizer with required arguments
13
  tokenizer = AutoTokenizer.from_pretrained(
14
- model_name,
15
- use_auth_token=api_token, # Authenticate with Hugging Face token
16
- trust_remote_code=True # Allow custom code from the repository
17
  )
18
  model = AutoModelForCausalLM.from_pretrained(
19
- model_name,
20
- use_auth_token=api_token, # Authenticate with Hugging Face token
21
- trust_remote_code=True # Allow custom code from the repository
 
 
22
  )
23
 
24
-
25
  # Define the function to process user input
26
  def generate_response(input_text):
27
  try:
28
  # Tokenize the input text
29
  inputs = tokenizer(input_text, return_tensors="pt")
30
-
31
  # Generate a response using the model
32
  outputs = model.generate(
33
  inputs["input_ids"],
34
- max_length=256, # Limit the output length
35
- num_return_sequences=1, # Generate a single response
36
- temperature=0.7, # Adjust for creativity vs. determinism
37
- top_p=0.9, # Nucleus sampling
38
- top_k=50 # Top-k sampling
39
  )
40
-
41
  # Decode and return the generated text
42
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
43
  return response
44
-
45
  except Exception as e:
46
  return f"Error: {str(e)}"
47
 
@@ -52,7 +53,7 @@ iface = gr.Interface(
52
  outputs="text",
53
  title="ContactDoctor Medical Assistant",
54
  description="Provide input symptoms or queries and get AI-powered medical advice.",
55
- enable_api=True # Enables API for external calls
56
  )
57
 
58
  # Launch the Gradio app
 
11
 
12
  # Load the Hugging Face model and tokenizer with required arguments
13
  tokenizer = AutoTokenizer.from_pretrained(
14
+ model_name,
15
+ token=api_token, # Use `token` instead of `use_auth_token`
16
+ trust_remote_code=True
17
  )
18
  model = AutoModelForCausalLM.from_pretrained(
19
+ model_name,
20
+ token=api_token,
21
+ trust_remote_code=True,
22
+ device_map="auto", # Efficiently allocate resources
23
+ torch_dtype=torch.float16 # Use half precision for faster inference
24
  )
25
 
 
26
  # Define the function to process user input
27
  def generate_response(input_text):
28
  try:
29
  # Tokenize the input text
30
  inputs = tokenizer(input_text, return_tensors="pt")
31
+
32
  # Generate a response using the model
33
  outputs = model.generate(
34
  inputs["input_ids"],
35
+ max_length=256,
36
+ num_return_sequences=1,
37
+ temperature=0.7,
38
+ top_p=0.9,
39
+ top_k=50
40
  )
41
+
42
  # Decode and return the generated text
43
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
44
  return response
45
+
46
  except Exception as e:
47
  return f"Error: {str(e)}"
48
 
 
53
  outputs="text",
54
  title="ContactDoctor Medical Assistant",
55
  description="Provide input symptoms or queries and get AI-powered medical advice.",
56
+ enable_api=True
57
  )
58
 
59
  # Launch the Gradio app