File size: 2,679 Bytes
38076a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53a08fc
 
 
 
 
66e0ab6
38076a5
 
 
 
 
 
 
 
 
 
66e0ab6
 
 
a3f7765
38076a5
a3f7765
53a08fc
38076a5
 
 
 
 
 
 
 
 
 
53a08fc
 
 
 
 
 
66e0ab6
53a08fc
 
e09d4a0
38076a5
53a08fc
 
 
7630cf9
a3f7765
 
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 gradio as gr
# import requests

# API_URL = "https://ai-research.quarkgen.ai/templedekho/vastu/v1"

# def get_vastu_advice(question, image_path):
#     # Open the image file and prepare for upload
#     with open(image_path, 'rb') as image_file:
#         files = {'image_path': image_file}
#         data = {'question': question, 'session_id': "Ab-5654654"}

#         response = requests.post(API_URL, files=files, data=data)

#     if response.status_code == 200:
#         answer = response.text
#         return "πŸ•‰οΈ Guruji says: πŸ™\n\n" + answer
#     else:
#         return f"Error: {response.json().get('error', 'Unknown error')}"

# # Gradio interface
# iface = gr.Interface(
#     fn=get_vastu_advice,
#     inputs=[
#         gr.Textbox(label="Question"),
#         gr.Image(type="filepath", label="Upload House Image (JPEG/PNG)")
#     ],
#     outputs=gr.Textbox(label="Vastu Prediction"),
#     title="πŸ•‰οΈ AI Vastu Astrologer πŸ•‰οΈ",
#     description = "Enter your House Structure to get personalized Vastu advice from the AI Guru Vastu."
# )

# if __name__ == "__main__":
#     iface.launch(share=True)

import gradio as gr
import requests

API_URL = "https://ai-research.quarkgen.ai/templedekho/vastu/v1"

def get_vastu_advice(question, image_path=None):
    """
    Get Vastu advice by sending a question and either an image or PDF to the API.
    """
    files = {}
    data = {'question': question, 'session_id': "Ab-5654654"}

    # Add image file if provided
    if image_path:
        files['image_path'] = open(image_path, 'rb')

    # # Add PDF file if provided
    # if pdf_path:
    #     files['image_path'] = open(image_path, 'rb')

    try:
        response = requests.post(API_URL, files=files, data=data)

        # Check response status
        if response.status_code == 200:
            answer = response.text
            return "πŸ•‰οΈ Guruji says: πŸ™\n\n" + answer
        else:
            return f"Error: {response.json().get('error', 'Unknown error')}"
    finally:
        # Close file handlers to prevent resource leaks
        for file in files.values():
            file.close()

# Gradio interface
iface = gr.Interface(
    fn=get_vastu_advice,
    inputs=[
        gr.Textbox(label="Question"),
        gr.File(type="filepath", label="Upload House Image (JPEG/PNG/PDF)"),
    ],
    outputs=gr.Textbox(label="Vastu Prediction"),
    title="πŸ•‰οΈ AI Vastu Astrologer πŸ•‰οΈ",
    description="Enter your House Structure to get personalized Vastu advice from the AI Guru Vastu. You can upload an image of your house or a blueprint in PDF format."
)

if __name__ == "__main__":
    iface.launch(share=True)