-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
13 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from flask import Flask, request, jsonify | ||
from naamkaran.generate import generate_names | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/generate_names', methods=['POST']) | ||
def generate_names_api(): | ||
# Get request data as JSON | ||
data = request.get_json() | ||
|
||
# Extract parameters from JSON data or set default values | ||
start_letter = data.get('start_letter', 'a') | ||
end_letter = data.get('end_letter', None) | ||
how_many = data.get('how_many', 1) | ||
max_length = data.get('max_length', 5) | ||
gender = data.get('gender', 'M') | ||
temperature = data.get('temperature', 0.5) | ||
|
||
# Generate names using the provided parameters | ||
names = generate_names( | ||
start_letter=start_letter, | ||
end_letter=end_letter, | ||
how_many=how_many, | ||
max_length=max_length, | ||
gender=gender, | ||
temperature=temperature | ||
) | ||
|
||
# Return the generated names as JSON | ||
return jsonify(names) | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import requests | ||
import json | ||
|
||
# API endpoint URL | ||
url = 'http://127.0.0.1:5000/generate_names' # Update with your actual URL if needed | ||
|
||
# Request payload (JSON data) | ||
data = { | ||
'start_letter': 'A', | ||
'how_many': 10 | ||
} | ||
|
||
# Send a POST request to the API | ||
response = requests.post(url, json=data) | ||
|
||
# Check if the request was successful (HTTP status code 200) | ||
if response.status_code == 200: | ||
# Parse the JSON response | ||
generated_names = response.json() | ||
|
||
# Print the generated names | ||
print("Generated Names:") | ||
for name in generated_names: | ||
print(name) | ||
else: | ||
print(f"Request failed with status code {response.status_code}") | ||
print(response.text) |