Spaces:
Sleeping
Sleeping
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 | |
# Initialize Flask app | |
app = Flask(__name__, template_folder="templates") | |
app.secret_key = os.urandom(24) | |
# β Enable Debug Mode | |
app.config["DEBUG"] = True | |
# β Salesforce Connection Setup | |
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)}") | |
# β ROUTE: List All Routes for Debugging | |
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}) | |
# β HOME ROUTE | |
def home(): | |
return jsonify({"message": "Welcome to Biryani Hub API. Use /register, /login, /menu, /index, or /routes to check available endpoints."}) | |
# β RENDER INDEX.HTML FOR REGISTER & LOGIN | |
def index_page(): | |
return render_template("index.html") | |
# β REGISTER API | |
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"}) | |
# β LOGIN API | |
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"}) | |
# β MENU API | |
def get_menu(): | |
print("β‘ Menu API hit") | |
return jsonify({"success": True, "menu": [{"name": "Biryani", "price": 10}]}) | |
# β START SERVER | |
if __name__ == "__main__": | |
print("β Starting Flask API Server on port 7860...") | |
serve(app, host="0.0.0.0", port=7860) | |