Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import json
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def create_template(name, image_url, category, prompt):
|
| 6 |
url = "https://ai-agent-backend-v50m.onrender.com/api/v1/templates/"
|
|
@@ -39,6 +41,17 @@ def get_templates(skip=0, limit=10):
|
|
| 39 |
except requests.RequestException as e:
|
| 40 |
return f"Request failed: {str(e)}"
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
st.title("AI Agent Template Creator")
|
| 43 |
|
| 44 |
# Create tabs for different functionalities
|
|
@@ -59,7 +72,7 @@ with tab1:
|
|
| 59 |
st.error("Please fill in all fields including the image URL.")
|
| 60 |
|
| 61 |
if image_url:
|
| 62 |
-
|
| 63 |
|
| 64 |
with tab2:
|
| 65 |
st.header("Existing Templates")
|
|
@@ -79,7 +92,7 @@ with tab2:
|
|
| 79 |
st.write(f"Category: {template.get('category', 'N/A')}")
|
| 80 |
st.write(f"Prompt: {template.get('prompt', 'N/A')}")
|
| 81 |
if template.get('image'):
|
| 82 |
-
|
| 83 |
st.write("---")
|
| 84 |
else:
|
| 85 |
st.error(f"Failed to fetch templates: {templates}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from io import BytesIO
|
| 6 |
|
| 7 |
def create_template(name, image_url, category, prompt):
|
| 8 |
url = "https://ai-agent-backend-v50m.onrender.com/api/v1/templates/"
|
|
|
|
| 41 |
except requests.RequestException as e:
|
| 42 |
return f"Request failed: {str(e)}"
|
| 43 |
|
| 44 |
+
def display_image_from_url(image_url):
|
| 45 |
+
try:
|
| 46 |
+
response = requests.get(image_url)
|
| 47 |
+
if response.status_code == 200:
|
| 48 |
+
image = Image.open(BytesIO(response.content))
|
| 49 |
+
st.image(image, caption="Template Image", use_column_width=True)
|
| 50 |
+
else:
|
| 51 |
+
st.error(f"Failed to load image from URL: {image_url}")
|
| 52 |
+
except Exception as e:
|
| 53 |
+
st.error(f"Error displaying image: {str(e)}")
|
| 54 |
+
|
| 55 |
st.title("AI Agent Template Creator")
|
| 56 |
|
| 57 |
# Create tabs for different functionalities
|
|
|
|
| 72 |
st.error("Please fill in all fields including the image URL.")
|
| 73 |
|
| 74 |
if image_url:
|
| 75 |
+
display_image_from_url(image_url)
|
| 76 |
|
| 77 |
with tab2:
|
| 78 |
st.header("Existing Templates")
|
|
|
|
| 92 |
st.write(f"Category: {template.get('category', 'N/A')}")
|
| 93 |
st.write(f"Prompt: {template.get('prompt', 'N/A')}")
|
| 94 |
if template.get('image'):
|
| 95 |
+
display_image_from_url(template['image'])
|
| 96 |
st.write("---")
|
| 97 |
else:
|
| 98 |
st.error(f"Failed to fetch templates: {templates}")
|