Spaces:
Runtime error
Runtime error
Update Main.py
Browse files
Main.py
CHANGED
@@ -1,52 +1,37 @@
|
|
1 |
-
import
|
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 |
-
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
|
|
|
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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|