Spaces:
Sleeping
Sleeping
import streamlit as st | |
import requests | |
import json | |
import os | |
# Retrieve the API key from environment variables | |
API_KEY = os.getenv('API_KEY') | |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/CodeLlama-7b-hf" | |
headers = {"Authorization": f"Bearer {API_KEY}"} | |
def generate_response(prompt): | |
data = { | |
"inputs": prompt | |
} | |
response = requests.post(API_URL, headers=headers, json=data) | |
if response.status_code == 200: | |
return response.json() | |
else: | |
st.error(f"Error: {response.status_code}") | |
st.error(response.text) | |
return None | |
def main(): | |
st.title("Code Assistant") | |
prompt = st.text_area("Enter your prompt", height=100) | |
if st.button("Submit"): | |
response = generate_response(prompt) | |
if response: | |
st.text_area("Response", value=json.dumps(response, indent=2), height=200) | |
if __name__ == "__main__": | |
main() | |