Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,32 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
import json
|
|
|
4 |
|
5 |
-
#
|
6 |
-
API_KEY =
|
7 |
-
|
8 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/CodeLlama-7b-hf"
|
|
|
9 |
|
10 |
def generate_response(prompt):
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
return None
|
22 |
|
23 |
def main():
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
if __name__ == "__main__":
|
32 |
-
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
import json
|
4 |
+
import os
|
5 |
|
6 |
+
# Retrieve the API key from environment variables
|
7 |
+
API_KEY = os.getenv('API_KEY')
|
|
|
8 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/CodeLlama-7b-hf"
|
9 |
+
headers = {"Authorization": f"Bearer {API_KEY}"}
|
10 |
|
11 |
def generate_response(prompt):
|
12 |
+
data = {
|
13 |
+
"inputs": prompt
|
14 |
+
}
|
15 |
+
response = requests.post(API_URL, headers=headers, json=data)
|
16 |
+
if response.status_code == 200:
|
17 |
+
return response.json()
|
18 |
+
else:
|
19 |
+
st.error(f"Error: {response.status_code}")
|
20 |
+
st.error(response.text)
|
21 |
+
return None
|
|
|
22 |
|
23 |
def main():
|
24 |
+
st.title("Code Assistant")
|
25 |
+
prompt = st.text_area("Enter your prompt", height=100)
|
26 |
+
if st.button("Submit"):
|
27 |
+
response = generate_response(prompt)
|
28 |
+
if response:
|
29 |
+
st.text_area("Response", value=json.dumps(response, indent=2), height=200)
|
30 |
|
31 |
if __name__ == "__main__":
|
32 |
+
main()
|