Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- Dockerfile +2 -1
- src/streamlit_app.py +14 -5
Dockerfile
CHANGED
|
@@ -22,8 +22,9 @@ RUN pip3 install -r requirements.txt
|
|
| 22 |
# Change ownership of the app directory
|
| 23 |
RUN chown -R streamlit:streamlit /app
|
| 24 |
|
| 25 |
-
# Set environment
|
| 26 |
ENV AUTH_TOKEN=""
|
|
|
|
| 27 |
|
| 28 |
# Set Streamlit configuration via environment variables
|
| 29 |
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
|
|
|
|
| 22 |
# Change ownership of the app directory
|
| 23 |
RUN chown -R streamlit:streamlit /app
|
| 24 |
|
| 25 |
+
# Set environment variables (these will be overridden at runtime)
|
| 26 |
ENV AUTH_TOKEN=""
|
| 27 |
+
ENV API_URL=""
|
| 28 |
|
| 29 |
# Set Streamlit configuration via environment variables
|
| 30 |
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
|
src/streamlit_app.py
CHANGED
|
@@ -11,18 +11,27 @@ st.set_page_config(page_title="Solidity Code Generator")
|
|
| 11 |
st.title("π οΈ Solidity Code Generator")
|
| 12 |
st.write("Enter a coding instruction and get Solidity code")
|
| 13 |
|
| 14 |
-
prompt = st.text_area("π¬ Instruction", height=150)
|
| 15 |
|
| 16 |
if st.button("π Generate Code"):
|
| 17 |
if not prompt.strip():
|
| 18 |
st.warning("Please enter a valid instruction.")
|
|
|
|
|
|
|
| 19 |
else:
|
| 20 |
with st.spinner("Generating..."):
|
| 21 |
try:
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
# Get the authorization token from environment variables
|
| 25 |
auth_token = os.getenv("AUTH_TOKEN")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
headers = {
|
| 27 |
"Authorization": f"Bearer {auth_token}"
|
| 28 |
}
|
|
@@ -55,6 +64,6 @@ if st.button("π Generate Code"):
|
|
| 55 |
except requests.exceptions.RequestException as e:
|
| 56 |
st.error("β Network error: Unable to connect to the service. Please try again later.")
|
| 57 |
except KeyError:
|
| 58 |
-
st.error("β Configuration error:
|
| 59 |
except Exception as e:
|
| 60 |
st.error("β An unexpected error occurred. Please try again later.")
|
|
|
|
| 11 |
st.title("π οΈ Solidity Code Generator")
|
| 12 |
st.write("Enter a coding instruction and get Solidity code")
|
| 13 |
|
| 14 |
+
prompt = st.text_area("π¬ Instruction", height=150, max_chars=1000, help="Keep your instruction clear and concise (max 1000 characters)")
|
| 15 |
|
| 16 |
if st.button("π Generate Code"):
|
| 17 |
if not prompt.strip():
|
| 18 |
st.warning("Please enter a valid instruction.")
|
| 19 |
+
elif len(prompt) > 1000: # Limit prompt length to prevent model crashes
|
| 20 |
+
st.warning("β οΈ Your instruction is too long. Please keep it under 1000 characters for better results.")
|
| 21 |
else:
|
| 22 |
with st.spinner("Generating..."):
|
| 23 |
try:
|
| 24 |
+
# Get the API URL and authorization token from environment variables
|
| 25 |
+
api_url = os.getenv("API_URL")
|
|
|
|
| 26 |
auth_token = os.getenv("AUTH_TOKEN")
|
| 27 |
+
|
| 28 |
+
# Check if required environment variables are set
|
| 29 |
+
if not api_url:
|
| 30 |
+
st.error("β Configuration error: API URL not found. Please set the API_URL environment variable.")
|
| 31 |
+
st.stop()
|
| 32 |
+
if not auth_token:
|
| 33 |
+
st.error("β Configuration error: Authentication token not found. Please set the AUTH_TOKEN environment variable.")
|
| 34 |
+
st.stop()
|
| 35 |
headers = {
|
| 36 |
"Authorization": f"Bearer {auth_token}"
|
| 37 |
}
|
|
|
|
| 64 |
except requests.exceptions.RequestException as e:
|
| 65 |
st.error("β Network error: Unable to connect to the service. Please try again later.")
|
| 66 |
except KeyError:
|
| 67 |
+
st.error("β Configuration error: Required environment variables not found.")
|
| 68 |
except Exception as e:
|
| 69 |
st.error("β An unexpected error occurred. Please try again later.")
|