Futuresony commited on
Commit
56a0180
·
verified ·
1 Parent(s): a151214

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -20,20 +20,24 @@ def fetch_message():
20
  if not message:
21
  return jsonify({"error": "No input provided."}), 400
22
 
23
- # Set parameters for text generation
24
- generation_params = {
25
- "temperature": 0.7, # Adjust creativity level
26
- "top_p": 0.9, # Use nucleus sampling
27
- "max_new_tokens": 512, # Limit the response length
28
- "repetition_penalty": 1.1 # Avoid repeating text
29
  }
30
 
 
31
  try:
32
- # Process the message using the Hugging Face model with a timeout of 5 minutes
33
- response = client.text_generation(message, params=generation_params, timeout=300)
 
 
 
34
  return jsonify({"response": response})
35
  except Exception as e:
36
- return jsonify({"error": f"Error processing request: {str(e)}"}), 500
37
 
38
  if __name__ == "__main__":
39
  # Use PORT environment variable or default to 7860
 
20
  if not message:
21
  return jsonify({"error": "No input provided."}), 400
22
 
23
+ # Model parameters
24
+ parameters = {
25
+ "temperature": 0.7, # Adjust creativity
26
+ "top_p": 0.9, # Top-p sampling
27
+ "max_new_tokens": 200, # Limit response length
28
+ "do_sample": True # Enable sampling for varied responses
29
  }
30
 
31
+ # Process the message using the Hugging Face model
32
  try:
33
+ response = client.text_generation(
34
+ message,
35
+ parameters=parameters,
36
+ timeout=300 # 5 minutes timeout
37
+ )
38
  return jsonify({"response": response})
39
  except Exception as e:
40
+ return jsonify({"error": str(e)}), 500
41
 
42
  if __name__ == "__main__":
43
  # Use PORT environment variable or default to 7860