wagnercosta commited on
Commit
35e452a
1 Parent(s): 2a2e438

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +5 -5
  2. phi3_instruct_graph.py +29 -15
app.py CHANGED
@@ -120,10 +120,10 @@ def create_graph(json_data):
120
  height="600px",
121
  directed=True,
122
  notebook=False,
123
- # bgcolor="#111827",
124
- # font_color="white"
125
- bgcolor="#FFFFFF",
126
- font_color="#111827"
127
  )
128
  nt.from_nx(G)
129
  nt.barnes_hut(
@@ -171,7 +171,6 @@ def process_and_visualize(text, model):
171
  with gr.Blocks(title="Phi-3 Mini 4k Instruct Graph (by Emergent Methods") as demo:
172
  gr.Markdown("# Phi-3 Mini 4k Instruct Graph (by Emergent Methods)")
173
  gr.Markdown("Extract a JSON graph from a text input and visualize it.")
174
-
175
  with gr.Row():
176
  with gr.Column(scale=1):
177
  input_model = gr.Dropdown(
@@ -206,5 +205,6 @@ with gr.Blocks(title="Phi-3 Mini 4k Instruct Graph (by Emergent Methods") as dem
206
  inputs=[input_text, input_model],
207
  outputs=[output_graph, output_entity_viz]
208
  )
 
209
 
210
  demo.launch(share=False)
 
120
  height="600px",
121
  directed=True,
122
  notebook=False,
123
+ bgcolor="#111827",
124
+ font_color="white"
125
+ # bgcolor="#FFFFFF",
126
+ # font_color="#111827"
127
  )
128
  nt.from_nx(G)
129
  nt.barnes_hut(
 
171
  with gr.Blocks(title="Phi-3 Mini 4k Instruct Graph (by Emergent Methods") as demo:
172
  gr.Markdown("# Phi-3 Mini 4k Instruct Graph (by Emergent Methods)")
173
  gr.Markdown("Extract a JSON graph from a text input and visualize it.")
 
174
  with gr.Row():
175
  with gr.Column(scale=1):
176
  input_model = gr.Dropdown(
 
205
  inputs=[input_text, input_model],
206
  outputs=[output_graph, output_entity_viz]
207
  )
208
+
209
 
210
  demo.launch(share=False)
phi3_instruct_graph.py CHANGED
@@ -48,10 +48,7 @@ class Phi3InstructGraph:
48
  return self.pipe(messages, **generation_args)
49
 
50
  def _get_messages(self, text):
51
- messages = [
52
- {
53
- "role": "system",
54
- "content": dedent("""\n
55
  A chat between a curious user and an artificial intelligence Assistant. The Assistant is an expert at identifying entities and relationships in text. The Assistant responds in JSON output only.
56
 
57
  The User provides text in the format:
@@ -79,17 +76,34 @@ class Phi3InstructGraph:
79
 
80
  {"type":"object","properties":{"nodes":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"type":{"type":"string"},"detailed_type":{"type":"string"}},"required":["id","type","detailed_type"],"additionalProperties":false}},"edges":{"type":"array","items":{"type":"object","properties":{"from":{"type":"string"},"to":{"type":"string"},"label":{"type":"string"}},"required":["from","to","label"],"additionalProperties":false}}},"required":["nodes","edges"],"additionalProperties":false}
81
  """)
82
- },
83
- {
84
- "role": "user",
85
- "content": dedent(f"""\n
86
- -------Text begin-------
87
- {text}
88
- -------Text end-------
89
- """)
90
- }
91
- ]
92
- return messages
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
 
95
  def extract(self, text):
 
48
  return self.pipe(messages, **generation_args)
49
 
50
  def _get_messages(self, text):
51
+ context = dedent("""\n
 
 
 
52
  A chat between a curious user and an artificial intelligence Assistant. The Assistant is an expert at identifying entities and relationships in text. The Assistant responds in JSON output only.
53
 
54
  The User provides text in the format:
 
76
 
77
  {"type":"object","properties":{"nodes":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"type":{"type":"string"},"detailed_type":{"type":"string"}},"required":["id","type","detailed_type"],"additionalProperties":false}},"edges":{"type":"array","items":{"type":"object","properties":{"from":{"type":"string"},"to":{"type":"string"},"label":{"type":"string"}},"required":["from","to","label"],"additionalProperties":false}}},"required":["nodes","edges"],"additionalProperties":false}
78
  """)
79
+
80
+ user_message = dedent(f"""\n
81
+ -------Text begin-------
82
+ {text}
83
+ -------Text end-------
84
+ """)
85
+
86
+ if self.model == "EmergentMethods/Phi-3-medium-128k-instruct-graph":
87
+ # model without system message
88
+ messages = [
89
+ {
90
+ "role": "user",
91
+ "content": f"{context}\n Input: {user_message}",
92
+ }
93
+ ]
94
+ return messages
95
+ else:
96
+ messages = [
97
+ {
98
+ "role": "system",
99
+ "content": context
100
+ },
101
+ {
102
+ "role": "user",
103
+ "content": user_message
104
+ }
105
+ ]
106
+ return messages
107
 
108
 
109
  def extract(self, text):