File size: 2,758 Bytes
22bea9a
66083bc
 
95585ab
66083bc
 
2fab7d3
 
96f1a3c
95585ab
2fab7d3
95585ab
96f1a3c
2fab7d3
 
 
96f1a3c
95585ab
22bea9a
96f1a3c
95585ab
96f1a3c
22bea9a
96f1a3c
66083bc
96f1a3c
66083bc
96f1a3c
66083bc
96f1a3c
 
 
66083bc
 
 
96f1a3c
66083bc
 
 
96f1a3c
66083bc
 
2fab7d3
96f1a3c
 
 
 
 
2fab7d3
96f1a3c
1a545f7
95585ab
 
4a27f85
95585ab
 
 
2fab7d3
4a27f85
 
2fab7d3
95585ab
96f1a3c
 
 
 
66083bc
 
 
 
 
 
96f1a3c
66083bc
4a27f85
66083bc
 
95585ab
 
 
22bea9a
96f1a3c
2fab7d3
78f832f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import torch
from flask import Flask, render_template, request, jsonify
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__)

# Check GPU availability
device = "cuda" if torch.cuda.is_available() else "cpu"

# Whisper ASR config
config = AutoConfig.from_pretrained("openai/whisper-small")
config.update({"timeout": 60})

# Salesforce connection
try:
    print("Connecting to Salesforce...")
    sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
    print("Connected successfully!")
except Exception as e:
    print(f"Salesforce connection failed: {str(e)}")

# API Routes

@app.route('/login', methods=['POST'])
def login():
    data = request.json
    email = data.get('email')
    phone_number = data.get('phone_number')

    if not email or not phone_number:
        return jsonify({'error': 'Missing required fields'}), 400

    try:
        existing_customer = sf.query(f"SELECT Id, Name FROM Customer_Login__c WHERE Email__c = '{email}' AND Phone_Number__c = '{phone_number}'")
        if existing_customer['totalSize'] > 0:
            return jsonify({'success': True, 'message': 'Login successful!', 'customer': existing_customer['records'][0]})
        else:
            return jsonify({'error': 'No user found. Please register first.'}), 404
    except Exception as e:
        return jsonify({'error': f'Failed to fetch user from Salesforce: {str(e)}'}), 500

@app.route("/submit", methods=["POST"])
def submit():
    data = request.json
    name = data.get('name')
    email = data.get('email')
    phone = data.get('phone')

    if not name or not email or not phone:
        return jsonify({'error': 'Missing data'}), 400

    try:
        existing_customer = sf.query(f"SELECT Id FROM Customer_Login__c WHERE Email__c = '{email}' AND Phone_Number__c = '{phone}'")
        if existing_customer['totalSize'] > 0:
            return jsonify({'success': False, 'message': 'User already registered. Please log in.'}), 409

        customer_login = sf.Customer_Login__c.create({
            'Name': name,
            'Email__c': email,
            'Phone_Number__c': phone
        })

        return jsonify({'success': True, 'message': 'Registration successful!', 'id': customer_login['id']}), 200

    except Exception as e:
        return jsonify({'error': str(e)}), 500

@app.route("/")
def index():
    return render_template("index.html")

# Start server
if __name__ == "__main__":
    serve(app, host="0.0.0.0", port=7860)