File size: 1,561 Bytes
1ef3d70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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("Classify", on_click=classify, args=[text1,text2])