Rishit commited on
Commit
e9e4ec6
·
verified ·
1 Parent(s): da2dec5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -25
app.py CHANGED
@@ -2,13 +2,11 @@ import gradio as gr
2
  import requests
3
 
4
  # Function to call the Flask API and return the LLM response
5
- def get_match_making_result(
6
- name1, year1, month1, day1, hour1, minute1, city1, country1,
7
- name2, year2, month2, day2, hour2, minute2, city2, country2, language
8
- ):
9
  # Define the API endpoint
10
  api_url = "https://ai-research.quarkgen.ai/templedekho/match_maker/v1"
11
-
12
  # Prepare the payload to send to the API
13
  data = {
14
  "name1": name1, "year1": year1, "month1": month1, "day1": day1, "hour1": hour1, "minute1": minute1, "city1": city1, "country1": country1,
@@ -22,16 +20,24 @@ def get_match_making_result(
22
 
23
  # Check if the request was successful
24
  if response.status_code == 200:
25
- return response.json().get("result", "No result returned from the server.")
 
 
 
26
  else:
27
- return f"Error: {response.status_code}, {response.text}"
 
 
28
  except Exception as e:
29
- return f"An error occurred: {str(e)}"
 
 
30
 
31
- # Create the Gradio interface
32
- def create_gradio_interface():
33
  with gr.Blocks() as interface:
34
- # Add input fields for Person 1
 
35
  with gr.Row():
36
  with gr.Column():
37
  name1 = gr.Textbox(label="Name (Person 1)", placeholder="Enter the name of Person 1")
@@ -43,7 +49,6 @@ def create_gradio_interface():
43
  city1 = gr.Textbox(label="Birth City (Person 1)", placeholder="Enter the city of birth")
44
  country1 = gr.Textbox(label="Birth Country (Person 1)", placeholder="Enter the country of birth")
45
 
46
- # Add input fields for Person 2
47
  with gr.Row():
48
  with gr.Column():
49
  name2 = gr.Textbox(label="Name (Person 2)", placeholder="Enter the name of Person 2")
@@ -55,31 +60,47 @@ def create_gradio_interface():
55
  city2 = gr.Textbox(label="Birth City (Person 2)", placeholder="Enter the city of birth")
56
  country2 = gr.Textbox(label="Birth Country (Person 2)", placeholder="Enter the country of birth")
57
 
58
- # Add language selection
59
  language = gr.Radio(
60
  choices=["EN", "HI"],
61
  label="Select Response Language",
62
- value="EN"
 
63
  )
 
 
 
 
64
 
65
- # Add a submit button and display the results
66
- result = gr.Textbox(label="Generated Match Making Result", placeholder="Result will be displayed here...")
 
 
 
 
67
  submit_btn = gr.Button("Submit")
68
-
69
- # Call the API when the button is clicked
70
  submit_btn.click(
71
- fn=get_match_making_result,
72
- inputs=[name1, year1, month1, day1, hour1, minute1, city1, country1, name2, year2, month2, day2, hour2, minute2, city2, country2, language],
73
- outputs=result
 
 
 
 
 
 
 
 
 
74
  )
75
 
76
  return interface
77
 
78
  # Start the Gradio interface
79
  if __name__ == "__main__":
80
- title = "AI Guru Match Maker"
81
- description = "Enter your and your partner's details below to get personalized astrological aspects and match-making predictions from the AI Guru."
82
 
83
- # Launch the Gradio interface
84
- interface = create_gradio_interface()
85
  interface.launch()
 
2
  import requests
3
 
4
  # Function to call the Flask API and return the LLM response
5
+ def get_match_making_result(chat_history, name1, year1, month1, day1, hour1, minute1, city1, country1,
6
+ name2, year2, month2, day2, hour2, minute2, city2, country2, language):
 
 
7
  # Define the API endpoint
8
  api_url = "https://ai-research.quarkgen.ai/templedekho/match_maker/v1"
9
+
10
  # Prepare the payload to send to the API
11
  data = {
12
  "name1": name1, "year1": year1, "month1": month1, "day1": day1, "hour1": hour1, "minute1": minute1, "city1": city1, "country1": country1,
 
20
 
21
  # Check if the request was successful
22
  if response.status_code == 200:
23
+ result = response.json().get("result", "No result returned from the server.")
24
+ # Update chat history with bot's response
25
+ chat_history.append(("AI Guru", result))
26
+ return chat_history
27
  else:
28
+ error_message = f"Error: {response.status_code}, {response.text}"
29
+ chat_history.append(("AI Guru", error_message))
30
+ return chat_history
31
  except Exception as e:
32
+ error_message = f"An error occurred: {str(e)}"
33
+ chat_history.append(("AI Guru", error_message))
34
+ return chat_history
35
 
36
+ # Create the Gradio chatbot interface
37
+ def create_gradio_chat_interface():
38
  with gr.Blocks() as interface:
39
+ chat_history = gr.Chatbot(label="AI Guru Match Maker Chat")
40
+
41
  with gr.Row():
42
  with gr.Column():
43
  name1 = gr.Textbox(label="Name (Person 1)", placeholder="Enter the name of Person 1")
 
49
  city1 = gr.Textbox(label="Birth City (Person 1)", placeholder="Enter the city of birth")
50
  country1 = gr.Textbox(label="Birth Country (Person 1)", placeholder="Enter the country of birth")
51
 
 
52
  with gr.Row():
53
  with gr.Column():
54
  name2 = gr.Textbox(label="Name (Person 2)", placeholder="Enter the name of Person 2")
 
60
  city2 = gr.Textbox(label="Birth City (Person 2)", placeholder="Enter the city of birth")
61
  country2 = gr.Textbox(label="Birth Country (Person 2)", placeholder="Enter the country of birth")
62
 
63
+ # Language selection
64
  language = gr.Radio(
65
  choices=["EN", "HI"],
66
  label="Select Response Language",
67
+ value="EN",
68
+ tooltip="Choose 'EN' for English or 'HI' for Hindi"
69
  )
70
+
71
+ # Message to input (acts as a conversation continuation)
72
+ with gr.Row():
73
+ user_message = gr.Textbox(label="Ask a question to AI Guru...", placeholder="Enter your question here")
74
 
75
+ # Function to update chat on each user input
76
+ def update_chat(chat_history, user_message):
77
+ chat_history.append(("User", user_message))
78
+ return chat_history, ""
79
+
80
+ # Submit button for both initiating chat and asking further questions
81
  submit_btn = gr.Button("Submit")
 
 
82
  submit_btn.click(
83
+ update_chat,
84
+ inputs=[chat_history, user_message],
85
+ outputs=[chat_history, user_message]
86
+ )
87
+
88
+ # Match making button to trigger the calculation
89
+ match_btn = gr.Button("Get Match Making Result")
90
+ match_btn.click(
91
+ get_match_making_result,
92
+ inputs=[chat_history, name1, year1, month1, day1, hour1, minute1, city1, country1,
93
+ name2, year2, month2, day2, hour2, minute2, city2, country2, language],
94
+ outputs=[chat_history]
95
  )
96
 
97
  return interface
98
 
99
  # Start the Gradio interface
100
  if __name__ == "__main__":
101
+ title = "AI Guru Match Maker Chat"
102
+ description = "Chat with AI Guru and get personalized astrological match-making predictions."
103
 
104
+ # Launch the Gradio chatbot interface
105
+ interface = create_gradio_chat_interface()
106
  interface.launch()