Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,32 @@
|
|
|
|
1 |
import requests
|
2 |
import json
|
3 |
-
import gradio as gr
|
4 |
|
5 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
'Content-Type':'application/json'
|
10 |
-
}
|
11 |
-
|
12 |
-
history=[]
|
13 |
|
14 |
def generate_response(prompt):
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
inputs=gr.Textbox(lines=4,placeholder="Enter your Prompt"),
|
38 |
-
outputs="text"
|
39 |
-
)
|
40 |
-
interface.launch(share=True)
|
|
|
1 |
+
import streamlit as st
|
2 |
import requests
|
3 |
import json
|
|
|
4 |
|
5 |
+
# Access the API key from Hugging Face Spaces secrets (assuming Streamlit Space)
|
6 |
+
API_KEY = st.secrets["API_KEY"] # Replace "API_KEY" with your actual secret key name
|
7 |
|
8 |
+
API_URL = "https://api-inference.huggingface.co/models/meta-llama/CodeLlama-7b-hf"
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def generate_response(prompt):
|
11 |
+
data = {
|
12 |
+
"inputs": prompt
|
13 |
+
}
|
14 |
+
headers = {"Authorization": f"Bearer {API_KEY}"} # Use f-string for dynamic insertion
|
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()
|
|
|
|
|
|
|
|