geethareddy commited on
Commit
ff592b1
·
verified ·
1 Parent(s): 498578c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -2,23 +2,13 @@ import gradio as gr
2
  import bcrypt
3
  from simple_salesforce import Salesforce
4
  from datetime import datetime
5
- import openai # if using Hugging Face-based model (replace with your Hugging Face API call logic)
6
 
7
  # Salesforce Connection
8
  sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
9
 
10
- # Hugging Face API Integration (example with GPT for generating offers)
11
- openai.api_key = "your-huggingface-api-key" # Replace with your Hugging Face API key
12
-
13
- def generate_offer(customer_name):
14
- # Example: Use Hugging Face to generate an offer for the customer
15
- prompt = f"Generate a personalized offer for {customer_name} for their meal order."
16
- response = openai.Completion.create(
17
- engine="text-davinci-003", # Using GPT-3 for the example, replace with Hugging Face model if needed
18
- prompt=prompt,
19
- max_tokens=50
20
- )
21
- return response.choices[0].text.strip()
22
 
23
  # Function to Hash Password
24
  def hash_password(password):
@@ -31,7 +21,7 @@ def verify_password(plain_password, hashed_password):
31
  # Function to handle order and store it in Salesforce
32
  def save_order_to_salesforce(order_details):
33
  try:
34
- # Use Hugging Face or any other service to generate offers or any AI processing
35
  offer = generate_offer(order_details['Customer_Name__c'])
36
 
37
  # Creating order data to save in Salesforce
@@ -66,6 +56,12 @@ def save_order_to_salesforce(order_details):
66
  except Exception as e:
67
  return f"Error while saving order to Salesforce: {str(e)}"
68
 
 
 
 
 
 
 
69
 
70
  # Signup and Login Functions
71
  def signup(name, email, phone, password):
@@ -144,7 +140,7 @@ with gr.Blocks() as app:
144
  login_button.click(
145
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value="Menu loaded"), "Login successful!")
146
  if login(email, password)[0] == "Login successful!" else (gr.update(), gr.update(), gr.update(), "Invalid email or password."),
147
- [login_email, login_password], [login_page, menu_page, login_output]
148
  )
149
  submit_signup.click(signup, [signup_name, signup_email, signup_phone, signup_password], signup_output)
150
  preference.change(lambda pref: filter_menu(pref), [preference], menu_output)
 
2
  import bcrypt
3
  from simple_salesforce import Salesforce
4
  from datetime import datetime
5
+ from transformers import pipeline # Hugging Face's transformer library
6
 
7
  # Salesforce Connection
8
  sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
9
 
10
+ # Load Hugging Face model for text generation (example: GPT-2 or T5 model)
11
+ generator = pipeline('text-generation', model='gpt2') # You can replace with a model of your choice
 
 
 
 
 
 
 
 
 
 
12
 
13
  # Function to Hash Password
14
  def hash_password(password):
 
21
  # Function to handle order and store it in Salesforce
22
  def save_order_to_salesforce(order_details):
23
  try:
24
+ # Use Hugging Face to generate an offer for the customer
25
  offer = generate_offer(order_details['Customer_Name__c'])
26
 
27
  # Creating order data to save in Salesforce
 
56
  except Exception as e:
57
  return f"Error while saving order to Salesforce: {str(e)}"
58
 
59
+ # Generate a personalized offer using Hugging Face model (you can replace with your own model)
60
+ def generate_offer(customer_name):
61
+ prompt = f"Generate a personalized discount offer for {customer_name} for their meal order."
62
+ result = generator(prompt, max_length=50, num_return_sequences=1)
63
+ offer = result[0]['generated_text']
64
+ return offer
65
 
66
  # Signup and Login Functions
67
  def signup(name, email, phone, password):
 
140
  login_button.click(
141
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value="Menu loaded"), "Login successful!")
142
  if login(email, password)[0] == "Login successful!" else (gr.update(), gr.update(), gr.update(), "Invalid email or password."),
143
+ [login_email, login_password], [login_page, menu_page, menu_output]
144
  )
145
  submit_signup.click(signup, [signup_name, signup_email, signup_phone, signup_password], signup_output)
146
  preference.change(lambda pref: filter_menu(pref), [preference], menu_output)