Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
API_URL = "https://ai-research.quarkgen.ai/templedekho/vastu/v1"
|
| 5 |
|
| 6 |
-
def get_vastu_advice(question, image_path):
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
|
|
|
| 12 |
response = requests.post(API_URL, files=files, data=data)
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Gradio interface
|
| 21 |
iface = gr.Interface(
|
| 22 |
fn=get_vastu_advice,
|
| 23 |
inputs=[
|
| 24 |
gr.Textbox(label="Question"),
|
| 25 |
-
gr.Image(type="filepath", label="Upload House Image (JPEG/PNG)")
|
|
|
|
| 26 |
],
|
| 27 |
outputs=gr.Textbox(label="Vastu Prediction"),
|
| 28 |
title="ποΈ AI Vastu Astrologer ποΈ",
|
| 29 |
-
description
|
| 30 |
)
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
# import requests
|
| 3 |
+
|
| 4 |
+
# API_URL = "https://ai-research.quarkgen.ai/templedekho/vastu/v1"
|
| 5 |
+
|
| 6 |
+
# def get_vastu_advice(question, image_path):
|
| 7 |
+
# # Open the image file and prepare for upload
|
| 8 |
+
# with open(image_path, 'rb') as image_file:
|
| 9 |
+
# files = {'image_path': image_file}
|
| 10 |
+
# data = {'question': question, 'session_id': "Ab-5654654"}
|
| 11 |
+
|
| 12 |
+
# response = requests.post(API_URL, files=files, data=data)
|
| 13 |
+
|
| 14 |
+
# if response.status_code == 200:
|
| 15 |
+
# answer = response.text
|
| 16 |
+
# return "ποΈ Guruji says: π\n\n" + answer
|
| 17 |
+
# else:
|
| 18 |
+
# return f"Error: {response.json().get('error', 'Unknown error')}"
|
| 19 |
+
|
| 20 |
+
# # Gradio interface
|
| 21 |
+
# iface = gr.Interface(
|
| 22 |
+
# fn=get_vastu_advice,
|
| 23 |
+
# inputs=[
|
| 24 |
+
# gr.Textbox(label="Question"),
|
| 25 |
+
# gr.Image(type="filepath", label="Upload House Image (JPEG/PNG)")
|
| 26 |
+
# ],
|
| 27 |
+
# outputs=gr.Textbox(label="Vastu Prediction"),
|
| 28 |
+
# title="ποΈ AI Vastu Astrologer ποΈ",
|
| 29 |
+
# description = "Enter your House Structure to get personalized Vastu advice from the AI Guru Vastu."
|
| 30 |
+
# )
|
| 31 |
+
|
| 32 |
+
# if __name__ == "__main__":
|
| 33 |
+
# iface.launch(share=True)
|
| 34 |
+
|
| 35 |
import gradio as gr
|
| 36 |
import requests
|
| 37 |
|
| 38 |
API_URL = "https://ai-research.quarkgen.ai/templedekho/vastu/v1"
|
| 39 |
|
| 40 |
+
def get_vastu_advice(question, image_path=None, pdf_path=None):
|
| 41 |
+
"""
|
| 42 |
+
Get Vastu advice by sending a question and either an image or PDF to the API.
|
| 43 |
+
"""
|
| 44 |
+
files = {}
|
| 45 |
+
data = {'question': question, 'session_id': "Ab-5654654"}
|
| 46 |
+
|
| 47 |
+
# Add image file if provided
|
| 48 |
+
if image_path:
|
| 49 |
+
files['image_path'] = open(image_path, 'rb')
|
| 50 |
+
|
| 51 |
+
# Add PDF file if provided
|
| 52 |
+
if pdf_path:
|
| 53 |
+
files['pdf_file'] = open(pdf_path, 'rb')
|
| 54 |
|
| 55 |
+
try:
|
| 56 |
response = requests.post(API_URL, files=files, data=data)
|
| 57 |
|
| 58 |
+
# Check response status
|
| 59 |
+
if response.status_code == 200:
|
| 60 |
+
answer = response.text
|
| 61 |
+
return "ποΈ Guruji says: π\n\n" + answer
|
| 62 |
+
else:
|
| 63 |
+
return f"Error: {response.json().get('error', 'Unknown error')}"
|
| 64 |
+
finally:
|
| 65 |
+
# Close file handlers to prevent resource leaks
|
| 66 |
+
for file in files.values():
|
| 67 |
+
file.close()
|
| 68 |
|
| 69 |
# Gradio interface
|
| 70 |
iface = gr.Interface(
|
| 71 |
fn=get_vastu_advice,
|
| 72 |
inputs=[
|
| 73 |
gr.Textbox(label="Question"),
|
| 74 |
+
gr.Image(type="filepath", label="Upload House Image (JPEG/PNG)", optional=True),
|
| 75 |
+
gr.File(type="file", label="Upload House Blueprint (PDF)", optional=True)
|
| 76 |
],
|
| 77 |
outputs=gr.Textbox(label="Vastu Prediction"),
|
| 78 |
title="ποΈ AI Vastu Astrologer ποΈ",
|
| 79 |
+
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."
|
| 80 |
)
|
| 81 |
|
| 82 |
if __name__ == "__main__":
|