Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,12 +20,20 @@ def fetch_message():
|
|
| 20 |
if not message:
|
| 21 |
return jsonify({"error": "No input provided."}), 400
|
| 22 |
|
| 23 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
try:
|
| 25 |
-
|
|
|
|
| 26 |
return jsonify({"response": response})
|
| 27 |
except Exception as e:
|
| 28 |
-
return jsonify({"error": str(e)}), 500
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
# Use PORT environment variable or default to 7860
|
|
|
|
| 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": 150, # 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
|