ramalMr commited on
Commit
d0ee1ab
·
verified ·
1 Parent(s): b54c869

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -20,8 +20,20 @@ def extract_sentences_from_excel(file):
20
  return sentences
21
 
22
  def save_to_json(data, filename="synthetic_data.json"):
23
- with open(filename, mode='a', encoding='utf-8') as file:
24
- json.dump(data, file, indent=4, ensure_ascii=False)
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def generate(file, prompt, temperature, max_new_tokens, top_p, repetition_penalty):
27
  sentences = extract_sentences_from_excel(file)
 
20
  return sentences
21
 
22
  def save_to_json(data, filename="synthetic_data.json"):
23
+ with open(filename, mode='w', encoding='utf-8') as file:
24
+ json_data = []
25
+ for item in data:
26
+ generated_sentences = []
27
+ confidence_scores = []
28
+ for match in re.finditer(r"{'generated_sentence': '(.+)', 'confidence_score': (\d+\.\d+)}", item['generated_data']):
29
+ generated_sentences.append(match.group(1))
30
+ confidence_scores.append(float(match.group(2)))
31
+ json_data.append({
32
+ 'original_sentence': item['original_sentence'],
33
+ 'generated_sentences': generated_sentences,
34
+ 'confidence_scores': confidence_scores
35
+ })
36
+ json.dump(json_data, file, indent=4, ensure_ascii=False)
37
 
38
  def generate(file, prompt, temperature, max_new_tokens, top_p, repetition_penalty):
39
  sentences = extract_sentences_from_excel(file)