chandralegend commited on
Commit
c813793
1 Parent(s): 46da71c

minor ui changes

Browse files
Files changed (2) hide show
  1. app.py +12 -23
  2. requirements.txt +2 -1
app.py CHANGED
@@ -3,11 +3,16 @@ import openai
3
  import os
4
  import re
5
  import ast
 
6
 
7
- st.title("Named Entity Recognition (NER) with GPT-3")
8
 
9
- if "guidelines" not in st.session_state:
10
- st.session_state["guidelines"] = [
 
 
 
 
11
  {
12
  "entity": "PERSON",
13
  "definition": "Short name or full name of a person from any geographic regions.",
@@ -24,24 +29,8 @@ if "guidelines" not in st.session_state:
24
  "color": "blue",
25
  },
26
  ]
27
-
28
-
29
- st.header("Guidelines")
30
-
31
- # display guidelines in a table
32
- st.table(st.session_state["guidelines"])
33
-
34
- st.write("You can add new guidelines here.")
35
- new_entity = st.text_input("Entity")
36
- new_definition = st.text_input("Definition")
37
- color = st.text_input("Color")
38
- if st.button("Add Guideline"):
39
- st.session_state["guidelines"].append(
40
- {"entity": new_entity, "definition": new_definition, "color": color}
41
- )
42
- new_entity = ""
43
- new_definition = ""
44
-
45
 
46
  examples = [
47
  {
@@ -57,7 +46,7 @@ examples = [
57
 
58
  def generate_guidelines_prompt(guidelines):
59
  guidelines_prompt = "Entity Definition:\n"
60
- for guideline in guidelines:
61
  guidelines_prompt += f"{guideline['entity']}: {guideline['definition']}\n"
62
  guidelines_prompt += "\nOutput Format:\n"
63
  guidelines_prompt += "{{'PERSON': [list of entities present], 'DATE': [list of entities present], 'LOC': [list of entities present]}}\n"
@@ -76,7 +65,7 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
76
  SYSTEM_PROMPT = "You are a smart and intelligent Named Entity Recognition (NER) system. I will provide you the definition of the entities you need to extract, the sentence from where your extract the entities and the output format with examples."
77
  USER_PROMPT_1 = "Are you clear about your role?"
78
  ASSISTANT_PROMPT_1 = "Sure, I'm ready to help you with your NER task. Please provide me with the necessary information to get started."
79
- GUIDELINES_PROMPT = generate_guidelines_prompt(st.session_state["guidelines"])
80
 
81
 
82
  def openai_chat_completion_response(final_prompt):
3
  import os
4
  import re
5
  import ast
6
+ import pandas as pd
7
 
8
+ st.title(":rocket: Named Entity Recognition (NER) with GPT-3")
9
 
10
+ # st.header("Guidelines")
11
+ st.markdown(
12
+ "You can edit the guidelines here. Press `Delete` to remove a row after selecting it."
13
+ )
14
+ df = pd.DataFrame(
15
+ [
16
  {
17
  "entity": "PERSON",
18
  "definition": "Short name or full name of a person from any geographic regions.",
29
  "color": "blue",
30
  },
31
  ]
32
+ )
33
+ edited_df = st.experimental_data_editor(df, num_rows="dynamic")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  examples = [
36
  {
46
 
47
  def generate_guidelines_prompt(guidelines):
48
  guidelines_prompt = "Entity Definition:\n"
49
+ for guideline in guidelines.values():
50
  guidelines_prompt += f"{guideline['entity']}: {guideline['definition']}\n"
51
  guidelines_prompt += "\nOutput Format:\n"
52
  guidelines_prompt += "{{'PERSON': [list of entities present], 'DATE': [list of entities present], 'LOC': [list of entities present]}}\n"
65
  SYSTEM_PROMPT = "You are a smart and intelligent Named Entity Recognition (NER) system. I will provide you the definition of the entities you need to extract, the sentence from where your extract the entities and the output format with examples."
66
  USER_PROMPT_1 = "Are you clear about your role?"
67
  ASSISTANT_PROMPT_1 = "Sure, I'm ready to help you with your NER task. Please provide me with the necessary information to get started."
68
+ GUIDELINES_PROMPT = generate_guidelines_prompt(edited_df.to_dict(orient="index"))
69
 
70
 
71
  def openai_chat_completion_response(final_prompt):
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  streamlit
2
- openai
 
1
  streamlit
2
+ openai
3
+ pandas