Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
import streamlit as st
|
2 |
from huggingface_hub import HfApi, create_repo, upload_file
|
3 |
-
from groq import Groq
|
4 |
import os
|
|
|
|
|
5 |
|
6 |
-
# Set up
|
7 |
-
|
8 |
-
|
9 |
|
10 |
# App title
|
11 |
st.title("HF DevAssist - Create and Manage Hugging Face Spaces")
|
@@ -50,25 +51,33 @@ if st.button("Generate and Deploy App"):
|
|
50 |
st.error("App description cannot be empty.")
|
51 |
else:
|
52 |
try:
|
53 |
-
# Generate app code using
|
54 |
-
st.info("Generating app code using
|
55 |
-
|
56 |
-
|
57 |
{
|
58 |
-
"
|
59 |
-
"content": (
|
60 |
-
f"Generate a Streamlit app based on this description: "
|
61 |
-
f"'{app_description}'"
|
62 |
-
),
|
63 |
}
|
64 |
-
]
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
# Create or update Hugging Face Space
|
74 |
space_full_name = f"{user_info['name']}/{space_name}"
|
|
|
1 |
import streamlit as st
|
2 |
from huggingface_hub import HfApi, create_repo, upload_file
|
|
|
3 |
import os
|
4 |
+
import requests
|
5 |
+
import json
|
6 |
|
7 |
+
# Set up Google API key
|
8 |
+
google_api_key = st.secrets["googleapi"]
|
9 |
+
google_api_url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key={google_api_key}"
|
10 |
|
11 |
# App title
|
12 |
st.title("HF DevAssist - Create and Manage Hugging Face Spaces")
|
|
|
51 |
st.error("App description cannot be empty.")
|
52 |
else:
|
53 |
try:
|
54 |
+
# Generate app code using Google API
|
55 |
+
st.info("Generating app code using Google API...")
|
56 |
+
payload = {
|
57 |
+
"contents": [
|
58 |
{
|
59 |
+
"parts": [{"text": f"Generate a Streamlit app with the following description: {app_description}. Include the app code followed by '### requirements.txt' and the dependencies required."}]
|
|
|
|
|
|
|
|
|
60 |
}
|
61 |
+
]
|
62 |
+
}
|
63 |
+
headers = {"Content-Type": "application/json"}
|
64 |
+
response = requests.post(google_api_url, headers=headers, json=payload)
|
65 |
+
|
66 |
+
if response.status_code != 200:
|
67 |
+
st.error(f"Google API request failed with status code {response.status_code}: {response.text}")
|
68 |
+
st.stop()
|
69 |
|
70 |
+
generated_code = response.json()["contents"][0]["parts"][0]["text"]
|
71 |
+
st.text_area("Debug: Google API Response", generated_code, height=150)
|
72 |
+
|
73 |
+
# Split generated code
|
74 |
+
try:
|
75 |
+
app_code, req_code = generated_code.split("### requirements.txt")
|
76 |
+
app_code = app_code.strip()
|
77 |
+
req_code = req_code.strip()
|
78 |
+
except ValueError:
|
79 |
+
st.error("The Google API response did not contain the expected sections. Please try again.")
|
80 |
+
st.stop()
|
81 |
|
82 |
# Create or update Hugging Face Space
|
83 |
space_full_name = f"{user_info['name']}/{space_name}"
|