Kailxzz commited on
Commit
39ae643
1 Parent(s): 075be13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -34
app.py CHANGED
@@ -1,40 +1,32 @@
 
1
  import requests
2
  import json
3
- import gradio as gr
4
 
5
- url="https://65ab-182-19-35-177.ngrok-free.app/api/generate"
 
6
 
7
- headers={
8
-
9
- 'Content-Type':'application/json'
10
- }
11
-
12
- history=[]
13
 
14
  def generate_response(prompt):
15
- history.append(prompt)
16
- final_prompt="\n".join(history)
17
-
18
- data={
19
- "model":"codingsensei",
20
- "prompt":final_prompt,
21
- "stream":False
22
- }
23
-
24
- response=requests.post(url,headers=headers,data=json.dumps(data))
25
-
26
- if response.status_code==200:
27
- response=response.text
28
- data=json.loads(response)
29
- actual_response=data['response']
30
- return actual_response
31
- else:
32
- print("error:",response.text)
33
-
34
-
35
- interface=gr.Interface(
36
- fn=generate_response,
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()