Update app.py
Browse files
app.py
CHANGED
@@ -29,44 +29,33 @@ def generate(file, temperature, max_new_tokens, top_p, repetition_penalty):
|
|
29 |
sentences = text.split('.')
|
30 |
random.shuffle(sentences) # Shuffle sentences
|
31 |
|
32 |
-
# CSV
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
|
52 |
-
try:
|
53 |
-
stream = client.text_generation(sentence, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
54 |
-
output = ""
|
55 |
-
for response in stream:
|
56 |
-
output += response.token.text
|
57 |
-
save_to_csv(sentence, output)
|
58 |
-
except Exception as e:
|
59 |
-
print(f"Error generating data for sentence '{sentence}': {e}")
|
60 |
-
save_to_csv(sentence, f"Error: {e}")
|
61 |
-
|
62 |
-
# CSV dosyasını okuyup byte olarak döndür
|
63 |
-
with open("synthetic_data.csv", "r", encoding="utf-8") as file:
|
64 |
-
csv_content = file.read()
|
65 |
-
csv_bytes = csv_content.encode()
|
66 |
-
|
67 |
-
# Geçici dosya oluştur ve içeriği yaz
|
68 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as tmp:
|
69 |
-
tmp.write(csv_bytes)
|
70 |
tmp_path = tmp.name
|
71 |
|
72 |
return tmp_path
|
|
|
29 |
sentences = text.split('.')
|
30 |
random.shuffle(sentences) # Shuffle sentences
|
31 |
|
32 |
+
# Geçici dosya oluştur ve CSV yazıcısını başlat
|
33 |
+
with tempfile.NamedTemporaryFile(mode='w', newline='', delete=False, suffix='.csv') as tmp:
|
34 |
+
writer = csv.writer(tmp)
|
35 |
+
|
36 |
+
for sentence in sentences:
|
37 |
+
sentence = sentence.strip()
|
38 |
+
if not sentence:
|
39 |
+
continue
|
40 |
|
41 |
+
generate_kwargs = {
|
42 |
+
"temperature": temperature,
|
43 |
+
"max_new_tokens": max_new_tokens,
|
44 |
+
"top_p": top_p,
|
45 |
+
"repetition_penalty": repetition_penalty,
|
46 |
+
"do_sample": True,
|
47 |
+
"seed": 42,
|
48 |
+
}
|
49 |
|
50 |
+
try:
|
51 |
+
stream = client.text_generation(sentence, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
52 |
+
output = ""
|
53 |
+
for response in stream:
|
54 |
+
output += response.token.text
|
55 |
+
writer.writerow([sentence, output]) # Orijinal cümle ve yanıt CSV'ye yazılır
|
56 |
+
except Exception as e:
|
57 |
+
print(f"Error generating data for sentence '{sentence}': {e}")
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
tmp_path = tmp.name
|
60 |
|
61 |
return tmp_path
|