Utkarsh Verma commited on
Commit
b90dee0
Β·
1 Parent(s): 7e80aef

Adding Docker File

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -7,7 +7,7 @@ app = Flask(__name__)
7
  # Set your Hugging Face API key
8
  HF_API_KEY = os.getenv("HF_API_KEY") # Store in environment variable
9
 
10
- API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
11
  headers = {"Authorization": f"Bearer {HF_API_KEY}"}
12
 
13
  @app.route('/')
@@ -22,24 +22,24 @@ def chat(user_input):
22
  return jsonify({"error": "Empty message received"})
23
 
24
  try:
25
- # payload = {
26
- # "inputs": f"[INST] {user_input} [/INST]",
27
- # "parameters": {
28
- # "temperature": 0.5, # πŸ”₯ Controls randomness (lower = more deterministic)
29
- # "top_p": 0.9, # 🎯 Focus on high-probability words
30
- # "max_new_tokens": 50, # ⏳ Limits response length
31
- # "stop_sequences": ["\nUser:", "[INST]"] # β›” Stops response at natural points
32
- # }
33
- # }
34
- response = requests.post(API_URL, headers=headers, json={"inputs": user_message})
35
  data = response.json()
36
- print(response.status_code) # Debugging: Print the HTTP status
37
- print(response.json()) # Debugging: Print the API response
38
 
39
- if response.status_code == 200:
40
- return response.json()[0]['generated_text']
41
- else:
42
- return f"Error: {response.status_code} - {response.json()}"
43
 
44
 
45
 
 
7
  # Set your Hugging Face API key
8
  HF_API_KEY = os.getenv("HF_API_KEY") # Store in environment variable
9
 
10
+ API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
11
  headers = {"Authorization": f"Bearer {HF_API_KEY}"}
12
 
13
  @app.route('/')
 
22
  return jsonify({"error": "Empty message received"})
23
 
24
  try:
25
+ payload = {
26
+ "inputs": f"[INST] {user_input} [/INST]",
27
+ "parameters": {
28
+ "temperature": 0.5, # πŸ”₯ Controls randomness (lower = more deterministic)
29
+ "top_p": 0.9, # 🎯 Focus on high-probability words
30
+ "max_new_tokens": 50, # ⏳ Limits response length
31
+ "stop_sequences": ["\nUser:", "[INST]"] # β›” Stops response at natural points
32
+ }
33
+ }
34
+ response = requests.post(API_URL, headers=headers, json=payload)
35
  data = response.json()
36
+ # print(response.status_code) # Debugging: Print the HTTP status
37
+ # print(response.json()) # Debugging: Print the API response
38
 
39
+ # if response.status_code == 200:
40
+ # return response.json()[0]['generated_text']
41
+ # else:
42
+ # return f"Error: {response.status_code} - {response.json()}"
43
 
44
 
45