mpolanco commited on
Commit
912f391
1 Parent(s): 65598e7

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +52 -37
model.py CHANGED
@@ -1,37 +1,52 @@
1
- import streamlit as st
2
- from model import GeneralModel
3
-
4
-
5
- def app():
6
-
7
- # Creating an object of prediction service
8
- pred = GeneralModel()
9
-
10
- api_key = st.sidebar.text_input("APIkey", type="password")
11
- # Using the streamlit cache
12
- @st.cache
13
- def process_prompt(input):
14
-
15
- return pred.model_prediction(input=input.strip() , api_key=api_key)
16
-
17
- if api_key:
18
-
19
- # Setting up the Title
20
- st.title("Escritor GPT-3")
21
-
22
- # st.write("---")
23
-
24
- s_example = "Escriba un ensayo argumentativo a favor de los vouchers escolares"
25
- input = st.text_area(
26
- "Use el ejemplo de abajo o escriba su propio texto en español",
27
- value=s_example,
28
- max_chars=1250,
29
- height=50,
30
- )
31
-
32
- if st.button("Submit"):
33
- with st.spinner(text="In progress"):
34
- report_text = process_prompt(input)
35
- st.markdown(report_text)
36
- else:
37
- st.error("🔑 Please enter API Key")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+
3
+ poem = """Escriba lo que se le pide:
4
+ ---
5
+ {input}
6
+ ---
7
+ Este es el resultado: """
8
+
9
+ def set_openai_key(key):
10
+ """Sets OpenAI key."""
11
+ openai.api_key = key
12
+
13
+ class GeneralModel:
14
+ def __init__(self):
15
+ print("Model Intilization--->")
16
+ # set_openai_key(API_KEY)
17
+
18
+ def query(self, prompt, myKwargs={}):
19
+ """
20
+ wrapper for the API to save the prompt and the result
21
+ """
22
+
23
+ # arguments to send the API
24
+ kwargs = {
25
+ "engine": "text-davinci-002",
26
+ "temperature": 0.85,
27
+ "max_tokens": 2400,
28
+ "best_of": 1,
29
+ "top_p": 1,
30
+ "frequency_penalty": 0.5,
31
+ "presence_penalty": 0.5,
32
+ "stop": ["###"],
33
+ }
34
+
35
+
36
+ for kwarg in myKwargs:
37
+ kwargs[kwarg] = myKwargs[kwarg]
38
+
39
+
40
+ r = openai.Completion.create(prompt=prompt, **kwargs)["choices"][0][
41
+ "text"
42
+ ].strip()
43
+ return r
44
+
45
+ def model_prediction(self, input, api_key):
46
+ """
47
+ wrapper for the API to save the prompt and the result
48
+ """
49
+ # Setting the OpenAI API key got from the OpenAI dashboard
50
+ set_openai_key(api_key)
51
+ output = self.query(poem.format(input = input))
52
+ return output