themeetjani's picture
Update pages/cg.py
c676944 verified
import streamlit as st
from streamlit import session_state
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
import pandas as pd
from sklearn.preprocessing import LabelEncoder
import numpy as np
def gpt4_score(schema, query):
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{
"role": "system",
"content": "You are Code generator assistant. your task is to generate a code/query based on the instructions given in any language.\nif it's sql then accept query instruction also.\n\n<<REMEMBER>> Give only code or query. Don't provide any extra information.\n\n<<OUTPUT>>"
},
{
"role": "user",
"content": f"Schema/ Detail: {schema}"
},
{
"role": "user",
"content": f"Query/instruction: {query}"
}
],
temperature=0.7,
max_tokens=701,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response.choices[0].message.content
st.write("# Auto Code Generation! 👋")
if 'score' not in session_state:
session_state['score']= ""
text1= st.text_area(label= "Please write the Schema or Detailed explaination bellow",
placeholder="What does the text say?")
text2= st.text_area(label= "Please write the Query or code instructions bellow",
placeholder="What does the text say?")
def classify(text1,text2):
session_state['score'] = gpt4_score(text1,text2)
st.text_area("result", value=session_state['score'])
st.button("Submit", on_click=classify, args=[text1,text2])