Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,36 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
nlp = pipeline("fill-mask", model=model_name)
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
st.
|
| 11 |
|
| 12 |
-
|
| 13 |
-
user_input = st.text_input("Enter a sentence in Finnish:")
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
# Use the model to predict masked words (as a simple example of language understanding)
|
| 19 |
-
masked_input = user_input.replace("____", "[MASK]")
|
| 20 |
-
results = nlp(masked_input)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
for result in example_results:
|
| 31 |
-
st.write(f"Prediction: {result['token_str']}, Score: {result['score']:.4f}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import openai
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Set your OpenAI API key here or set it as an environment variable
|
| 6 |
+
openai.api_key = os.getenv("OPENAI_API_KEY", "sk-None-RVvMry6BpMfG8KxYS6hTT3BlbkFJSOfj2bCwA1EmTRrAHo5y")
|
|
|
|
| 7 |
|
| 8 |
+
# Function to classify lines using GPT-3
|
| 9 |
+
def classify_lines_with_gpt3(text):
|
| 10 |
+
response = openai.Completion.create(
|
| 11 |
+
engine="text-davinci-003",
|
| 12 |
+
prompt=f"Classify the following Finnish contract specifications into categories: Urakka sisältää: Urakka ei sisältää: Tilaajan velvoitteet:Käytäntöjen tarkennukset:Hintojen tarkennukset: Muu:.\n\n{text}\n\n",
|
| 13 |
+
max_tokens=1024,
|
| 14 |
+
n=1,
|
| 15 |
+
stop=None,
|
| 16 |
+
temperature=0.5,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
classified_text = response.choices[0].text.strip()
|
| 20 |
+
return classified_text
|
| 21 |
|
| 22 |
+
st.title("Finnish Contract Specifications Categorizer with GPT-3")
|
| 23 |
|
| 24 |
+
st.write("Enter the contract specifications in Finnish:")
|
|
|
|
| 25 |
|
| 26 |
+
# Text area for large text input
|
| 27 |
+
contract_text = st.text_area("Contract Specifications (Finnish):", height=300)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
if st.button("Classify"):
|
| 30 |
+
if contract_text:
|
| 31 |
+
classified_text = classify_lines_with_gpt3(contract_text)
|
| 32 |
|
| 33 |
+
st.write("Classified Contract Specifications:")
|
| 34 |
+
st.write(classified_text)
|
| 35 |
+
else:
|
| 36 |
+
st.write("Please enter the contract specifications.")
|
|
|
|
|
|