Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -118,9 +118,14 @@ def llama_generate(
|
|
| 118 |
eos_token_id=llama_tokenizer.eos_token_id,
|
| 119 |
|
| 120 |
)
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
torch.cuda.empty_cache()
|
| 123 |
-
return output_text
|
| 124 |
|
| 125 |
|
| 126 |
def generate_explanation(issue_text, top_quality):
|
|
@@ -130,30 +135,23 @@ def generate_explanation(issue_text, top_quality):
|
|
| 130 |
|
| 131 |
quality_name = top_quality[0][0] # Get the name of the top quality
|
| 132 |
|
| 133 |
-
prompt = f"""
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
try:
|
| 146 |
explanation = llama_generate(prompt)
|
| 147 |
-
|
| 148 |
-
#
|
| 149 |
-
|
| 150 |
-
if cleaned_explanation.lower().startswith(quality_name.lower()):
|
| 151 |
-
cleaned_explanation = cleaned_explanation[len(quality_name):].strip()
|
| 152 |
-
if cleaned_explanation.startswith(":"):
|
| 153 |
-
cleaned_explanation = cleaned_explanation[1:].strip()
|
| 154 |
-
|
| 155 |
-
# Format for better readability
|
| 156 |
-
formatted_explanation = f"<div class='explanation-box'><p><b>Why this is a {quality_name} issue:</b></p><p>{cleaned_explanation}</p></div>"
|
| 157 |
return formatted_explanation
|
| 158 |
except Exception as e:
|
| 159 |
logging.error(f"Error during Llama generation: {e}")
|
|
@@ -280,9 +278,9 @@ interface = gr.Interface(
|
|
| 280 |
gr.Markdown(label="Explanation")
|
| 281 |
],
|
| 282 |
title="QualityTagger",
|
| 283 |
-
description="This tool classifies text into different quality domains such as Security, Usability,Mantainability, Reliability etc., and provides explanations.",
|
| 284 |
examples=example_texts,
|
| 285 |
css=css,
|
| 286 |
cache_examples=False# Apply the CSS
|
| 287 |
)
|
| 288 |
-
interface.launch(
|
|
|
|
| 118 |
eos_token_id=llama_tokenizer.eos_token_id,
|
| 119 |
|
| 120 |
)
|
| 121 |
+
|
| 122 |
+
# Extract only the newly generated tokens
|
| 123 |
+
input_length = inputs.input_ids.shape[1]
|
| 124 |
+
generated_tokens = generate_ids[0][input_length:]
|
| 125 |
+
|
| 126 |
+
output_text = llama_tokenizer.decode(generated_tokens, skip_special_tokens=True)
|
| 127 |
torch.cuda.empty_cache()
|
| 128 |
+
return output_text.strip()
|
| 129 |
|
| 130 |
|
| 131 |
def generate_explanation(issue_text, top_quality):
|
|
|
|
| 135 |
|
| 136 |
quality_name = top_quality[0][0] # Get the name of the top quality
|
| 137 |
|
| 138 |
+
prompt = f"""Analyze the following issue description based on the quality dimension: {quality_name}.
|
| 139 |
|
| 140 |
+
Issue Description:
|
| 141 |
+
---
|
| 142 |
+
{issue_text}
|
| 143 |
+
---
|
| 144 |
|
| 145 |
+
1. **Justification**: Briefly explain why this issue fails or relates to {quality_name}.
|
| 146 |
+
2. **Improved Version**: Suggest how to rewrite the issue description to better meet this quality standard (e.g., making it more clear, concise, or actionable).
|
| 147 |
|
| 148 |
+
Provide your response directly without preamble. Use a clear separation between the justification and the rewrite."""
|
| 149 |
+
|
| 150 |
try:
|
| 151 |
explanation = llama_generate(prompt)
|
| 152 |
+
|
| 153 |
+
# Format for better readability. Using linebreaks helps Gradio's Markdown component parse it correctly inside the HTML block.
|
| 154 |
+
formatted_explanation = f"<div class='explanation-box'>\n\n### Why this is a {quality_name} issue:\n\n{explanation}\n\n</div>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
return formatted_explanation
|
| 156 |
except Exception as e:
|
| 157 |
logging.error(f"Error during Llama generation: {e}")
|
|
|
|
| 278 |
gr.Markdown(label="Explanation")
|
| 279 |
],
|
| 280 |
title="QualityTagger",
|
| 281 |
+
description="This tool classifies text into different quality domains such as Security, Usability, Mantainability, Reliability etc., and provides explanations.",
|
| 282 |
examples=example_texts,
|
| 283 |
css=css,
|
| 284 |
cache_examples=False# Apply the CSS
|
| 285 |
)
|
| 286 |
+
interface.launch()
|