rosemariafontana commited on
Commit
f7278cf
·
verified ·
1 Parent(s): 7c59728

in theory added interactions

Browse files
Files changed (1) hide show
  1. app.py +32 -17
app.py CHANGED
@@ -11,22 +11,22 @@ os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
11
  client = OpenAI()
12
 
13
  # These are the necessary components that make up the Interactions
14
- #class Role(str, Enum):
15
- # PARTNER = 'partner'
16
- # STAFF = 'staff'
17
- # AGRONOMIST = 'agronomist'
18
- # OTHER = 'other'
19
 
20
- #class Person(BaseModel):
21
- # name: str = Field(..., title="Name", description="Name of this person")
22
- # role: Role = Field(..., title="Role", description="Role of this person")
23
 
24
- #class Interactions(BaseModel):
25
- # people: List[Person] = Field(..., title="People", description="People involved or mentioned during interaction")
26
- # date: str = Field(..., title="Date of current interaction", description="Date of the interaction")
27
- # nextMeeting: str = Field(..., title="Date of next meeting", description="Proposed date of the next future interaction")
28
- # nextSteps: List[str] = Field(..., title="Next Steps", description="List of individual next steps derived from the interaction")
29
- # summary: str = Field(..., title="Summary", description="Summary of the interaction")
30
 
31
  # These are the components for Farm Activities, Fields, and Plantings
32
  class Status(str, Enum):
@@ -133,10 +133,24 @@ def generate_json(specification, model_version):
133
 
134
  pretty_json = generated_json.json()
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  if 'error' in response:
137
  raise ValueError(f"API error: {response['error']['message']}")
138
 
139
- return pretty_json
140
 
141
  except ValidationError as e:
142
  return {"error": str(e)}
@@ -249,7 +263,8 @@ with gr.Blocks() as demo:
249
  soil_data_input = gr.Textbox(label="Enter your soil data", placeholder="Description, Structure, Biology", visible=False)
250
  yield_data_input = gr.Textbox(label="Enter your yield data", placeholder="Quantity, Quality", visible=False)
251
 
252
- output_box = gr.Textbox(label="JSON Data Output")
 
253
 
254
  def update_visibility(radio, additional_options):
255
  value = radio
@@ -274,7 +289,7 @@ with gr.Blocks() as demo:
274
  submit_button.click(
275
  fn=process_specifications,
276
  inputs=[data_input, model_version_input, json_creation_input, additional_json_creation_options, field_data_input, planting_data_input, logs_data_input, soil_data_input, yield_data_input],
277
- outputs=[output_box]
278
  )
279
 
280
  clear_button = gr.ClearButton(components=[data_input, model_version_input, json_creation_input, additional_json_creation_options, field_data_input, planting_data_input, logs_data_input, soil_data_input, yield_data_input])
 
11
  client = OpenAI()
12
 
13
  # These are the necessary components that make up the Interactions
14
+ class Role(str, Enum):
15
+ PARTNER = 'partner'
16
+ STAFF = 'staff'
17
+ AGRONOMIST = 'agronomist'
18
+ OTHER = 'other'
19
 
20
+ class Person(BaseModel):
21
+ name: str = Field(..., title="Name", description="Name of this person")
22
+ role: Role = Field(..., title="Role", description="Role of this person")
23
 
24
+ class Interactions(BaseModel):
25
+ people: List[Person] = Field(..., title="People", description="People involved or mentioned during interaction")
26
+ date: str = Field(..., title="Date of current interaction", description="Date of the interaction")
27
+ nextMeeting: str = Field(..., title="Date of next meeting", description="Proposed date of the next future interaction")
28
+ nextSteps: List[str] = Field(..., title="Next Steps", description="List of individual next steps derived from the interaction")
29
+ summary: str = Field(..., title="Summary", description="Summary of the interaction")
30
 
31
  # These are the components for Farm Activities, Fields, and Plantings
32
  class Status(str, Enum):
 
133
 
134
  pretty_json = generated_json.json()
135
 
136
+ another_response = client.beta.chat.completions.parse(
137
+ model=model_version, # Use GPT model that supports structured output
138
+ messages=[
139
+ {"role": "system", "content": "Extract the farm information."},
140
+ {"role": "user", "content": specification}
141
+ ],
142
+ response_format=Interactions,
143
+ )
144
+
145
+ another_generated_json = another_response.choices[0].message.parsed
146
+ print(another_generated_json) # debugging 2
147
+
148
+ another_pretty_json = another_generated_json.json()
149
+
150
  if 'error' in response:
151
  raise ValueError(f"API error: {response['error']['message']}")
152
 
153
+ return pretty_json, another_pretty_json
154
 
155
  except ValidationError as e:
156
  return {"error": str(e)}
 
263
  soil_data_input = gr.Textbox(label="Enter your soil data", placeholder="Description, Structure, Biology", visible=False)
264
  yield_data_input = gr.Textbox(label="Enter your yield data", placeholder="Quantity, Quality", visible=False)
265
 
266
+ output_box = gr.Textbox(label="Fields and Activities Data")
267
+ another_output_box = gr.Textbox(label="Interactions Data")
268
 
269
  def update_visibility(radio, additional_options):
270
  value = radio
 
289
  submit_button.click(
290
  fn=process_specifications,
291
  inputs=[data_input, model_version_input, json_creation_input, additional_json_creation_options, field_data_input, planting_data_input, logs_data_input, soil_data_input, yield_data_input],
292
+ outputs=[output_box, another_output_box]
293
  )
294
 
295
  clear_button = gr.ClearButton(components=[data_input, model_version_input, json_creation_input, additional_json_creation_options, field_data_input, planting_data_input, logs_data_input, soil_data_input, yield_data_input])