|
import torch |
|
from flask import Flask, render_template, request, jsonify, redirect, session, url_for |
|
import json |
|
import os |
|
from transformers import pipeline |
|
from gtts import gTTS |
|
from pydub import AudioSegment |
|
from pydub.silence import detect_nonsilent |
|
from transformers import AutoConfig |
|
import time |
|
from waitress import serve |
|
from simple_salesforce import Salesforce |
|
import requests |
|
|
|
|
|
app = Flask(__name__, template_folder="templates") |
|
app.secret_key = os.urandom(24) |
|
|
|
|
|
app.config["DEBUG"] = True |
|
|
|
|
|
try: |
|
print("Attempting to connect to Salesforce...") |
|
sf = Salesforce(username='[email protected]', |
|
password='Sati@1020', |
|
security_token='sSSjyhInIsUohKpG8sHzty2q') |
|
print("β
Connected to Salesforce successfully!") |
|
except Exception as e: |
|
print(f"β Failed to connect to Salesforce: {str(e)}") |
|
|
|
|
|
@app.route("/routes", methods=["GET"]) |
|
def list_routes(): |
|
routes = [] |
|
for rule in app.url_map.iter_rules(): |
|
routes.append({"endpoint": rule.endpoint, "route": str(rule)}) |
|
return jsonify({"available_routes": routes}) |
|
|
|
|
|
@app.route("/", methods=["GET"]) |
|
def home(): |
|
return jsonify({"message": "Welcome to Biryani Hub API. Use /register, /login, /menu, /index, or /routes to check available endpoints."}) |
|
|
|
|
|
@app.route("/index", methods=["GET"]) |
|
def index_page(): |
|
return render_template("index.html") |
|
|
|
|
|
@app.route("/register", methods=["POST"]) |
|
def register(): |
|
print("β‘ Register API hit") |
|
data = request.json |
|
if not data or "name" not in data or "email" not in data or "phone" not in data: |
|
return jsonify({"error": "Missing required fields"}), 400 |
|
return jsonify({"success": True, "message": "Registration successful"}) |
|
|
|
|
|
@app.route("/login", methods=["POST"]) |
|
def login(): |
|
print("β‘ Login API hit") |
|
data = request.json |
|
if not data or "email" not in data or "phone" not in data: |
|
return jsonify({"error": "Missing email or phone"}), 400 |
|
return jsonify({"success": True, "message": "Login successful"}) |
|
|
|
|
|
@app.route("/menu", methods=["GET"]) |
|
def get_menu(): |
|
print("β‘ Menu API hit") |
|
return jsonify({"success": True, "menu": [{"name": "Biryani", "price": 10}]}) |
|
|
|
|
|
if __name__ == "__main__": |
|
print("β
Starting Flask API Server on port 7860...") |
|
serve(app, host="0.0.0.0", port=7860) |
|
|