Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,32 +80,36 @@ def enhance_for_gradio(prompt_text, api_key):
|
|
| 80 |
try:
|
| 81 |
result = pipe(
|
| 82 |
messages,
|
| 83 |
-
max_new_tokens=
|
| 84 |
temperature=0.7,
|
| 85 |
do_sample=True
|
| 86 |
-
# stop_strings kaldırıldı - test için
|
| 87 |
)
|
| 88 |
full_response = result[0]["generated_text"]
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
if isinstance(full_response, list):
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
# String ise direkt kullan
|
| 100 |
-
enhanced_prompt = full_response
|
| 101 |
-
|
| 102 |
-
# Temizlik
|
| 103 |
-
enhanced_prompt = enhanced_prompt.replace("<end_of_turn>", "").strip()
|
| 104 |
-
|
| 105 |
-
if not enhanced_prompt:
|
| 106 |
-
return "Model did not generate a valid response. Try again."
|
| 107 |
-
|
| 108 |
-
return enhanced_prompt
|
| 109 |
|
| 110 |
except Exception as e:
|
| 111 |
return f"Enhancement failed: {str(e)}"
|
|
|
|
| 80 |
try:
|
| 81 |
result = pipe(
|
| 82 |
messages,
|
| 83 |
+
max_new_tokens=1024, # Artırıldı
|
| 84 |
temperature=0.7,
|
| 85 |
do_sample=True
|
|
|
|
| 86 |
)
|
| 87 |
full_response = result[0]["generated_text"]
|
| 88 |
+
|
| 89 |
+
print("=== MODEL OUTPUT ===")
|
| 90 |
+
print(full_response)
|
| 91 |
+
print("=== END OUTPUT ===")
|
| 92 |
+
|
| 93 |
+
# Manuel parse denemesi
|
| 94 |
+
if isinstance(full_response, str):
|
| 95 |
+
# Kullanıcı prompt'unu bul ve sonrasını al
|
| 96 |
+
if prompt_text in full_response:
|
| 97 |
+
idx = full_response.find(prompt_text) + len(prompt_text)
|
| 98 |
+
enhanced_prompt = full_response[idx:].strip()
|
| 99 |
+
# <end_of_turn> varsa kaldır
|
| 100 |
+
enhanced_prompt = enhanced_prompt.replace("<end_of_turn>", "").strip()
|
| 101 |
+
if enhanced_prompt:
|
| 102 |
+
return enhanced_prompt
|
| 103 |
+
|
| 104 |
+
# Veya assistant mesajını bulmaya çalış
|
| 105 |
if isinstance(full_response, list):
|
| 106 |
+
for msg in reversed(full_response):
|
| 107 |
+
if msg.get("role") == "assistant":
|
| 108 |
+
content = msg.get("content", "").replace("<end_of_turn>", "").strip()
|
| 109 |
+
if content:
|
| 110 |
+
return content
|
| 111 |
+
|
| 112 |
+
return "Model did not generate a valid response. Please check the console output."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
except Exception as e:
|
| 115 |
return f"Enhancement failed: {str(e)}"
|