ramalMr commited on
Commit
aebf89a
·
verified ·
1 Parent(s): 231908c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -10,6 +10,7 @@ import io
10
  import tempfile
11
  import re
12
 
 
13
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
14
 
15
  def extract_sentences_from_excel(file):
@@ -33,7 +34,7 @@ def generate(file, prompt, temperature, max_new_tokens, top_p, repetition_penalt
33
  all_outputs = []
34
  for sentence in sentences:
35
  try:
36
- stream = client.text_generation(f"{prompt} Output the response in the following JSON format: {{'generated_sentence': 'The generated sentence text', 'confidence_score': 0.9}} {sentence}", **generate_kwargs, stream=True, details=True, return_full_text=False)
37
  output = ""
38
  for response in stream:
39
  output += response.token.text
@@ -56,11 +57,8 @@ def generate(file, prompt, temperature, max_new_tokens, top_p, repetition_penalt
56
  def save_to_json(data, filename):
57
  json_data = []
58
  for item in data:
59
- generated_sentences = []
60
- confidence_scores = []
61
- for match in re.finditer(r"{'generated_sentence': '(.+?)', 'confidence_score': ([\d\.]+)}", item['generated_data']):
62
- generated_sentences.append(match.group(1))
63
- confidence_scores.append(float(match.group(2)))
64
  json_data.append({
65
  'original_sentence': item['original_sentence'],
66
  'generated_sentences': generated_sentences,
 
10
  import tempfile
11
  import re
12
 
13
+
14
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
15
 
16
  def extract_sentences_from_excel(file):
 
34
  all_outputs = []
35
  for sentence in sentences:
36
  try:
37
+ stream = client.text_generation(f"{prompt} {sentence}", **generate_kwargs, stream=True, details=True, return_full_text=False)
38
  output = ""
39
  for response in stream:
40
  output += response.token.text
 
57
  def save_to_json(data, filename):
58
  json_data = []
59
  for item in data:
60
+ generated_sentences = re.findall(r"{'generated_sentence': '(.+?)'", item['generated_data'])
61
+ confidence_scores = [0.9] * len(generated_sentences) # Varsayılan güven skoru
 
 
 
62
  json_data.append({
63
  'original_sentence': item['original_sentence'],
64
  'generated_sentences': generated_sentences,