Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .gitignore +6 -0
- Dockerfile +22 -0
- README.md +1 -1
- requirements.txt +5 -3
- src/streamlit_app.py +59 -39
.gitignore
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.streamlit/secrets.toml
|
| 2 |
+
src/.streamlit/secrets.toml
|
| 3 |
+
.streamlit/
|
| 4 |
+
src/.streamlit/
|
| 5 |
+
.env
|
| 6 |
+
*.env
|
Dockerfile
CHANGED
|
@@ -9,13 +9,35 @@ RUN apt-get update && apt-get install -y \
|
|
| 9 |
git \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
COPY requirements.txt ./
|
| 13 |
COPY src/ ./src/
|
| 14 |
|
| 15 |
RUN pip3 install -r requirements.txt
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
EXPOSE 8501
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 20 |
|
| 21 |
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
|
|
|
| 9 |
git \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
+
# Create a non-root user
|
| 13 |
+
RUN useradd -m -u 1000 streamlit
|
| 14 |
+
RUN mkdir -p /home/streamlit/.streamlit
|
| 15 |
+
RUN chown -R streamlit:streamlit /home/streamlit
|
| 16 |
+
|
| 17 |
COPY requirements.txt ./
|
| 18 |
COPY src/ ./src/
|
| 19 |
|
| 20 |
RUN pip3 install -r requirements.txt
|
| 21 |
|
| 22 |
+
# Change ownership of the app directory
|
| 23 |
+
RUN chown -R streamlit:streamlit /app
|
| 24 |
+
|
| 25 |
+
# Set environment variable (this will be overridden at runtime)
|
| 26 |
+
ENV AUTH_TOKEN=""
|
| 27 |
+
|
| 28 |
+
# Set Streamlit configuration via environment variables
|
| 29 |
+
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
|
| 30 |
+
ENV STREAMLIT_SERVER_PORT=8501
|
| 31 |
+
ENV STREAMLIT_SERVER_ENABLE_CORS=false
|
| 32 |
+
ENV STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION=false
|
| 33 |
+
ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
|
| 34 |
+
ENV STREAMLIT_GLOBAL_DEVELOPMENT_MODE=false
|
| 35 |
+
|
| 36 |
EXPOSE 8501
|
| 37 |
|
| 38 |
+
# Switch to non-root user
|
| 39 |
+
USER streamlit
|
| 40 |
+
|
| 41 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 42 |
|
| 43 |
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: π
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: red
|
|
|
|
| 1 |
---
|
| 2 |
+
title: SolidityLLMDemo
|
| 3 |
emoji: π
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: red
|
requirements.txt
CHANGED
|
@@ -1,3 +1,5 @@
|
|
| 1 |
-
altair
|
| 2 |
-
pandas
|
| 3 |
-
streamlit
|
|
|
|
|
|
|
|
|
| 1 |
+
altair
|
| 2 |
+
pandas
|
| 3 |
+
streamlit
|
| 4 |
+
python-dotenv
|
| 5 |
+
requests
|
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,60 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
""
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# Load environment variables
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
st.set_page_config(page_title="Solidity Code Generator")
|
| 10 |
+
|
| 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 |
+
api_url = "http://5339246508730216.us-east-1.pai-eas.aliyuncs.com/api/predict/test_llm_service/generate"
|
| 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 |
+
}
|
| 29 |
+
|
| 30 |
+
response = requests.post(api_url, json={"prompt": prompt}, stream=True, headers=headers)
|
| 31 |
+
response.raise_for_status()
|
| 32 |
+
|
| 33 |
+
# Get only the code from the JSON response
|
| 34 |
+
result = response.json()
|
| 35 |
+
solidity_code = result.get("code", "")
|
| 36 |
+
|
| 37 |
+
if solidity_code:
|
| 38 |
+
st.code(solidity_code, language="solidity")
|
| 39 |
+
else:
|
| 40 |
+
st.warning("Received an empty response from the Deployed Model.")
|
| 41 |
+
|
| 42 |
+
except requests.exceptions.Timeout:
|
| 43 |
+
st.error("β Request timed out. The service is taking too long to respond. Please try again.")
|
| 44 |
+
except requests.exceptions.ConnectionError:
|
| 45 |
+
st.error("β Network error: Unable to connect to the service. Please check your internet connection.")
|
| 46 |
+
except requests.exceptions.HTTPError as e:
|
| 47 |
+
if e.response.status_code == 503:
|
| 48 |
+
st.error("β Service temporarily unavailable. The AI service is currently down. Please try again later.")
|
| 49 |
+
elif e.response.status_code == 401:
|
| 50 |
+
st.error("β Authentication failed. Please check your API token.")
|
| 51 |
+
elif e.response.status_code == 403:
|
| 52 |
+
st.error("β Access denied. Please check your API permissions.")
|
| 53 |
+
else:
|
| 54 |
+
st.error(f"β HTTP Error {e.response.status_code}: {e.response.text}")
|
| 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: Authentication token not found.")
|
| 59 |
+
except Exception as e:
|
| 60 |
+
st.error("β An unexpected error occurred. Please try again later.")
|