Spaces:
Sleeping
Sleeping
import streamlit as st | |
from code_editor import code_editor | |
import random | |
import time | |
import requests | |
import os | |
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1" | |
headers = {"Authorization": f"Bearer {os.environ.get('API_KEY')}"} | |
def query(payload): | |
response = requests.post(API_URL, headers=headers, json=payload) | |
return response.json() | |
st.markdown(f":blue_background[Create] Code With AI") | |
st.write("Real-time Code Generation & Code Editor") | |
lang = st.selectbox("Choose Language", ["Python", "Javascript", "HTML", "C++", "CS", "Markdown", "Java", "C", "Go", "Ruby"]) | |
code = code_editor("Your Code Here", height=[1, 200], lang=lang) | |
if st.button("Run AI"): | |
output = query({ | |
"inputs": f"Can you please correct and improve this code, as output give only updated code; code to correct and improve: {code}", | |
}) | |
if output: | |
code = code_editor(output, height=[1, 200], lang=lang) |