Rishit commited on
Commit
54266f6
·
verified ·
1 Parent(s): 4593a54

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # API endpoint URL for the Horoscope API
5
+ API_URL = "https://ai-research.quarkgen.ai/templedekho/v1/horoscope"
6
+
7
+ def get_horoscope_response(name, year, month, day, hour, minutes, city, nation, question):
8
+ """
9
+ Send a POST request to the horoscope API with the user-provided parameters.
10
+ """
11
+ # Prepare the input payload
12
+ payload = {
13
+ "name": name,
14
+ "year": int(year),
15
+ "month": int(month),
16
+ "day": int(day),
17
+ "hour": int(hour),
18
+ "minutes": int(minutes),
19
+ "city": city,
20
+ "nation": nation,
21
+ "question": question
22
+ }
23
+
24
+ response = requests.post(API_URL, json=payload)
25
+
26
+
27
+ # Check if there was an error in the API response
28
+ if response.status_code == 200:
29
+ response_data = response.text
30
+ # return response_data
31
+ return response_data
32
+
33
+ else:
34
+ return "Sorry, there was an error with your request."
35
+
36
+
37
+ # Define the Gradio interface
38
+ def create_gradio_interface():
39
+ """
40
+ Creates the Gradio user interface for AI Guru Astrologer.
41
+ """
42
+ # Title and description for the interface
43
+ title = "AI Guru Astrologer"
44
+ description = "Enter your details below to get personalized horoscope predictions from the AI Guru Astrologer."
45
+
46
+ # Input components for the user's details (using gr.components instead of gr.inputs)
47
+ name_input = gr.Textbox(label="Name", placeholder="Enter your name")
48
+ year_input = gr.Number(label="Year of Birth")
49
+ month_input = gr.Number(label="Month of Birth")
50
+ day_input = gr.Number(label="Day of Birth")
51
+ hour_input = gr.Number(label="Hour of Birth (24-hour format)")
52
+ minutes_input = gr.Number(label="Minute of Birth")
53
+ city_input = gr.Textbox(label="City of Birth", placeholder="Enter the city of your birth")
54
+ nation_input = gr.Textbox(label="Nation (Country Code)", placeholder="Enter the country code (e.g., IN)")
55
+ question_input = gr.Textbox(label="Your Question for the Guru", placeholder="Enter your personal question (e.g., What is my career path?)")
56
+
57
+ # Output component for the response (using gr.components instead of gr.outputs)
58
+ response_output = gr.Textbox(label="AI Guru Astrologer's Response")
59
+
60
+ # Gradio interface layout
61
+ iface = gr.Interface(
62
+ fn=get_horoscope_response,
63
+ inputs=[name_input, year_input, month_input, day_input, hour_input, minutes_input, city_input, nation_input, question_input],
64
+ outputs=[response_output],
65
+ title=title,
66
+ description=description,
67
+ live=False, # The API call will be made when the user clicks the submit button
68
+ allow_flagging="never" # Disable flagging option
69
+ )
70
+
71
+ iface.launch(server_name="0.0.0.0", server_port=8709, share=True)
72
+
73
+ # Main entry point to run the Gradio interface
74
+ if __name__ == "__main__":
75
+ create_gradio_interface()