Nuthanon commited on
Commit
5b6c885
·
verified ·
1 Parent(s): d289308

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -23
app.py CHANGED
@@ -1,31 +1,36 @@
1
  import streamlit as st
2
- from transformers import pipeline
 
3
 
4
- # Load the pre-trained Finnish model
5
- model_name = "TurkuNLP/bert-base-finnish-cased-v1"
6
- nlp = pipeline("fill-mask", model=model_name)
7
 
8
- st.title("Finnish Language Understanding App")
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- st.write("This app demonstrates understanding of the Finnish language.")
11
 
12
- # User input
13
- user_input = st.text_input("Enter a sentence in Finnish:")
14
 
15
- if user_input:
16
- st.write("You entered:", user_input)
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
- st.write("Predictions for the masked word:")
23
- for result in results:
24
- st.write(f"Prediction: {result['token_str']}, Score: {result['score']:.4f}")
25
 
26
- if st.checkbox("Show example usage"):
27
- st.write("Example sentence: Hän on ____ ystävä.")
28
- example_results = nlp("Hän on [MASK] ystävä.")
29
- st.write("Predictions for the masked word in the example:")
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.")