# 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)