xiomarablanco commited on
Commit
1b6df82
1 Parent(s): 3ed3f4a

Using new inputs

Browse files
Files changed (3) hide show
  1. app.py +61 -10
  2. assets/qa.txt +11 -0
  3. codeScripts/settings.py +1 -1
app.py CHANGED
@@ -8,14 +8,28 @@ import pandas as pd
8
  import zipfile
9
  import os
10
 
11
- def Main(configuration, uploadedFile):
12
 
13
  error = ""
14
  modelResult = ""
15
 
16
- configuration_dict = json.loads(configuration)
17
-
18
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  if not uploadedFile:
20
  uploadedFilePath = "./assets/test_data.zip"
21
  else:
@@ -23,18 +37,50 @@ def Main(configuration, uploadedFile):
23
 
24
  config_json = load_json("configV2.json")
25
 
26
- #configuring plentas methodology
27
- response = Plentas(config_json[0], [answersTodict(uploadedFilePath), createTeacherJson(configuration_dict)])
28
- # #overwriting the custom settings for the settings from the api
 
 
29
  response.setApiSettings(configuration)
30
 
31
- # modelResult = jsonify(response.processApiData())
32
  modelResult = json.dumps(response.processApiData())
33
  except Exception as e:
34
  error = "Oops: " + str(e)
35
 
36
  return [error, modelResult]
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  def createTeacherJson(configuration):
39
  """
40
  This function extracts the information about the subquestions and subanswers and puts them in the correct format.
@@ -141,15 +187,20 @@ def answersTodict(zip_path):
141
  save_json(create_file_path('ApiStudentsDict.json', doctype= 1),studentAnswersDict)
142
  return studentAnswersDict
143
 
144
- configuration = gr.inputs.Textbox(lines=10, placeholder="JSON de Configuración")
145
- zipFileInput = gr.inputs.File(label="ZIP file")
 
 
 
 
 
146
  #dataFrameOutput = gr.outputs.Dataframe(headers=["Resultados"], max_rows=20, max_cols=None, overflow_row_behaviour="paginate", type="pandas", label="Resultado")
147
 
148
  labelOutput = gr.outputs.Label(num_top_classes=None, type="auto", label="")
149
  labelError = gr.outputs.Label(num_top_classes=None, type="auto", label="")
150
 
151
  iface = gr.Interface(fn=Main
152
- , inputs=[configuration, zipFileInput]
153
  , outputs=[labelError, labelOutput]
154
  , title = "PLENTAS"
155
  )
 
8
  import zipfile
9
  import os
10
 
11
+ def Main(uploadedFile, txtFileInput, orthographyPercentage, syntaxPercentage, semanticPercentage, studentsRange):
12
 
13
  error = ""
14
  modelResult = ""
15
 
 
 
16
  try:
17
+ if not txtFileInput:
18
+ txtFileInput = "./assets/qa.txt"
19
+ else:
20
+ txtFileInput = txtFileInput.name
21
+
22
+ configuration = readQATextFile(txtFileInput)
23
+
24
+ configuration["ortographyPercentage"] = float(orthographyPercentage)
25
+ configuration["syntaxPercentage"] = float(syntaxPercentage)
26
+ configuration["semanticPercentage"] = float(semanticPercentage)
27
+
28
+ if studentsRange == "":
29
+ studentsRange = "All"
30
+
31
+ configuration["students"] = studentsRange
32
+
33
  if not uploadedFile:
34
  uploadedFilePath = "./assets/test_data.zip"
35
  else:
 
37
 
38
  config_json = load_json("configV2.json")
39
 
40
+ modelResult = json.dumps(configuration)
41
+
42
+ # #configuring plentas methodology
43
+ response = Plentas(config_json[0], [answersTodict(uploadedFilePath), createTeacherJson(configuration)])
44
+ # # #overwriting the custom settings for the settings from the api
45
  response.setApiSettings(configuration)
46
 
47
+ # # modelResult = jsonify(response.processApiData())
48
  modelResult = json.dumps(response.processApiData())
49
  except Exception as e:
50
  error = "Oops: " + str(e)
51
 
52
  return [error, modelResult]
53
 
54
+ def readQATextFile(qaTextFilePath):
55
+ configuration = {}
56
+
57
+ f = open(qaTextFilePath, 'r')
58
+ lines = f.readlines()
59
+
60
+ count = 0
61
+ qCount=1
62
+
63
+ q = ""
64
+ a = ""
65
+ while count < len(lines):
66
+ if q == "" or q == "\n":
67
+ q = lines[count]
68
+ count += 1
69
+ continue
70
+
71
+ if a == "" or a == "\n":
72
+ a = lines[count]
73
+ count += 1
74
+
75
+ if q != "" and a != "":
76
+ configuration["minip" + str(qCount)] = q
77
+ configuration["minir" + str(qCount)] = a
78
+ qCount += 1
79
+ q = ""
80
+ a = ""
81
+
82
+ return configuration
83
+
84
  def createTeacherJson(configuration):
85
  """
86
  This function extracts the information about the subquestions and subanswers and puts them in the correct format.
 
187
  save_json(create_file_path('ApiStudentsDict.json', doctype= 1),studentAnswersDict)
188
  return studentAnswersDict
189
 
190
+
191
+ zipFileInput = gr.inputs.File(label="1. Selecciona el .ZIP con las respuestas de los alumnos")
192
+ txtFileInput = gr.inputs.File(label="2. Selecciona el .txt con las preguntas y respuestas correctas. Escriba una pregunta en una sola línea y debajo la respuesta en la línea siguiente.")
193
+ orthographyPercentage = gr.inputs.Textbox(label="Ortografía",lines=1, placeholder="0",default=0.1, numeric=1)
194
+ syntaxPercentage = gr.inputs.Textbox(label="Sintaxis",lines=1, placeholder="0",default=0.1,numeric=1)
195
+ semanticPercentage = gr.inputs.Textbox(label="Semántica",lines=1, placeholder="0",default=0.8, numeric=1)
196
+ studentsRange = gr.inputs.Textbox(label="Estudiantes a evaluar",lines=1, placeholder="Dejar vacío para evaluar todos")
197
  #dataFrameOutput = gr.outputs.Dataframe(headers=["Resultados"], max_rows=20, max_cols=None, overflow_row_behaviour="paginate", type="pandas", label="Resultado")
198
 
199
  labelOutput = gr.outputs.Label(num_top_classes=None, type="auto", label="")
200
  labelError = gr.outputs.Label(num_top_classes=None, type="auto", label="")
201
 
202
  iface = gr.Interface(fn=Main
203
+ , inputs=[zipFileInput, txtFileInput, orthographyPercentage, syntaxPercentage, semanticPercentage, studentsRange]
204
  , outputs=[labelError, labelOutput]
205
  , title = "PLENTAS"
206
  )
assets/qa.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Esta es la primera pregunta. Que puede tener varias oraciones en una sola línea.
2
+ Aquí va la primera respuesta.
3
+
4
+ Esta es la segunda pregunta.
5
+ Y esta es la segunda respuesta.
6
+
7
+ Ahora la tercera pregunta.
8
+ Y aquí la tercera respuesta.
9
+
10
+ Y la última pregunta.
11
+ Con la última respuesta.
codeScripts/settings.py CHANGED
@@ -31,7 +31,7 @@ class GetSettings():
31
  -api_settings: dictionary with the stored parameters from the api
32
  """
33
  #transforming string dict into dict
34
- api_settings = json.loads(api_settings)
35
 
36
  self.PesoOrtografia = api_settings["ortographyPercentage"]
37
  self.PesoSintaxis = api_settings["syntaxPercentage"]
 
31
  -api_settings: dictionary with the stored parameters from the api
32
  """
33
  #transforming string dict into dict
34
+ #api_settings = json.loads(api_settings)
35
 
36
  self.PesoOrtografia = api_settings["ortographyPercentage"]
37
  self.PesoSintaxis = api_settings["syntaxPercentage"]