syubraj commited on
Commit
b7c1cf4
·
verified ·
1 Parent(s): e706855

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +56 -27
README.md CHANGED
@@ -39,52 +39,81 @@ import torch
39
  # Clear CUDA memory before using the model
40
  torch.cuda.empty_cache()
41
 
42
- model_name = "syubraj/Phi-3.5-mini-instruct-MedicalChat"
43
- generator = pipeline("text-generation", model=model_name, device=-1) # Use CPU
44
 
45
- def generate_response(user_query, system_message=None, max_length=256):
 
 
 
 
 
 
46
  """
47
  Generates a response based on the given user query.
48
-
49
  :param user_query: The user's input message.
50
  :param system_message: Custom system instruction (optional, defaults to medical assistant).
51
  :param max_length: Max tokens to generate.
52
  :return: Generated assistant response.
53
  """
54
- if system_message is None:
55
- system_message = (
56
- "You are a trusted AI-powered medical assistant. "
57
- "Analyze patient queries carefully and provide accurate, professional, and empathetic responses. "
58
- "Prioritize patient safety, adhere to medical best practices, and recommend consulting a healthcare provider when necessary."
59
- )
60
 
61
- prompt = f"""<|system|> {system_message} <|end|>
62
- <|user|> {user_query} <|end|>
63
- <|assistant|>"""
 
64
 
65
- output = generator(prompt, max_length=max_length, truncation=True)
66
- response = output[0]["generated_text"].split("<|assistant|>")[-1].strip().split("<|end|>")[0].strip()
67
 
68
- return response
 
 
 
 
 
 
69
 
70
- # Example Usage
71
  user_input = "Hi Doctor, How to increase my height? I am 23 years old."
72
- assistant_reply = generate_response(user_input)
73
- print("\nAssistant Response:\n", assistant_reply)
 
74
  ```
75
 
76
  ### 📝 Example Output
77
- ```text
78
- Assistant Response:
79
- Hello! I understand that you're interested in increasing your height, and it's great that you're seeking advice at a young age.
80
- Here are some points to consider:
81
 
82
- 1. **Genetics**: The most significant factor in determining your height is genetics. You can't change your genetic makeup, but understanding your family's height patterns can give you an idea of your potential.
83
 
84
- 2. **Nutrition**: Ensure you're getting a balanced diet rich in calcium, protein, and vitamins D and A, which are essential for bone growth and development.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
- 3. **Healthy Habits**: Regular exercise, especially weight-bearing activities like walking, running, or resistance training, can help maintain bone health and potentially contribute.
87
- ```
88
 
89
  ---
90
 
 
39
  # Clear CUDA memory before using the model
40
  torch.cuda.empty_cache()
41
 
42
+ model_name = "syubraj/MedicalChat-Phi-3.5-mini-instruct"
 
43
 
44
+ try:
45
+ generator = pipeline("text-generation", model=model_name)
46
+ print("Pipeline loaded successfully.")
47
+ except Exception as e:
48
+ raise ValueError(f"Error loading pipeline: {e}")
49
+
50
+ def generate_response(user_query: str, system_message: str = None, max_length: int = 1024) -> str:
51
  """
52
  Generates a response based on the given user query.
53
+
54
  :param user_query: The user's input message.
55
  :param system_message: Custom system instruction (optional, defaults to medical assistant).
56
  :param max_length: Max tokens to generate.
57
  :return: Generated assistant response.
58
  """
59
+ if not user_query.strip():
60
+ return "Error: User query cannot be empty."
 
 
 
 
61
 
62
+ if system_message is None:
63
+ system_message = ("You are a trusted AI-powered medical assistant. "
64
+ "Analyze patient queries carefully and provide accurate, professional, and empathetic responses. "
65
+ "Prioritize patient safety, adhere to medical best practices, and recommend consulting a healthcare provider when necessary.")
66
 
67
+ prompt = f"<|system|> {system_message} <|end|> <|user|> {user_query} <|end|> <|assistant|>"
 
68
 
69
+ try:
70
+ outputs = generator(prompt, max_length=max_length, truncation=True)
71
+ response = outputs[0]["generated_text"].split("<|assistant|>")[-1].strip().split("<|end|>")[0].strip()
72
+ except Exception as e:
73
+ return f"Error generating response: {e}"
74
+
75
+ return response if response else "Error: No response generated."
76
 
 
77
  user_input = "Hi Doctor, How to increase my height? I am 23 years old."
78
+ response = generate_response(user_input)
79
+ print("Assistant Response:", response)
80
+
81
  ```
82
 
83
  ### 📝 Example Output
 
 
 
 
84
 
85
+ Assistant Response: Hello! I understand that you're looking to potentially increase your height, and I'll do my best to provide you with helpful information.
86
 
87
+ Firstly, it's important to clarify that after puberty, the growth plates in our bones, known as epiphyseal plates, have typically fused, meaning our height generally stabilizes. For most adults, especially those who have reached their late teens or early twenties, further height increase is unlikely.
88
+
89
+ However, there are a few factors that can influence your height:
90
+
91
+ 1. **Genetics**: Your genes play a significant role in determining your height. If your parents are tall, you might be taller too.
92
+
93
+ 2. **Nutrition**: Proper nutrition is essential for growth. Ensure you're getting a balanced diet with enough protein, calcium, and vitamins.
94
+
95
+ 3. **Posture**: Sometimes, poor posture can make you appear shorter. Practicing good posture might help you look taller.
96
+
97
+ 4. **Sleep**: Adequate sleep is crucial for growth hormones to work effectively.
98
+
99
+ 5. **Exercise**: Regular exercise can help maintain a healthy posture and spine alignment, which might help you appear taller.
100
+
101
+ Here are some tips that might help you look taller:
102
+
103
+ - **Stand Straight**: Keep your shoulders back and your back straight. This can make you appear taller.
104
+
105
+ - **Practice Good Posture**: Be mindful of your posture throughout the day.
106
+
107
+ - **Exercise**: Engage in exercises that strengthen your core, back, and leg muscles.
108
+
109
+ - **Shoe Lifts**: Some people find that wearing shoe lifts can make them appear taller. However, this is more of a visual effect and won't actually increase your height.
110
+
111
+ - **Physical Therapy**: If you have concerns about your posture or spinal alignment, a physical therapist can provide exercises and treatments to help.
112
+
113
+ Remember, while these tips might help you look taller, they won't change your actual height. If you're concerned about your height for medical reasons, such as a growth hormone deficiency, it's best to consult with a healthcare provider.
114
+
115
+ I hope this information is helpful! If you have any more questions or need further assistance, feel free to ask.
116
 
 
 
117
 
118
  ---
119