from flask import Flask, request, jsonify import requests app = Flask(__name__) # Hugging Face API URL and token HUGGING_FACE_API_URL = 'https://api-inference.huggingface.co/models/dnnsdunca/Llama-3-70B-DDroidlabs' API_TOKEN = 'your api key' @app.route('/generate-code', methods=['POST']) def generate_code(): data = request.get_json() prompt = data['prompt'] headers = { 'Authorization': f'Bearer {API_TOKEN}', 'Content-Type': 'application/json' } payload = { 'inputs': prompt, } response = requests.post(HUGGING_FACE_API_URL, headers=headers, json=payload) if response.status_code == 200: result = response.json() code = result[0]['generated_text'].strip() return jsonify({'code': code}) else: return jsonify({'error': 'Error generating code'}), 500 if __name__ == '__main__': app.run(port=8000)