muhammad-mujtaba-ai commited on
Commit
7d4b3f6
Β·
verified Β·
1 Parent(s): 4570bfa

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. .gitignore +6 -0
  2. Dockerfile +22 -0
  3. README.md +1 -1
  4. requirements.txt +5 -3
  5. 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: ChainGPT Solidity LLM 2
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
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
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.")