Julien Matuszak commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,7 +60,7 @@ def softmax(x):
|
|
| 60 |
return exp_x / exp_x.sum()
|
| 61 |
|
| 62 |
# Function to detect context
|
| 63 |
-
def detect_context(input_text, threshold=0.
|
| 64 |
# Encode the input text
|
| 65 |
inputs = tokenizer([input_text], padding=True, truncation=True, return_tensors="pt")
|
| 66 |
with torch.no_grad():
|
|
@@ -100,7 +100,7 @@ def process_request(input_text):
|
|
| 100 |
context_results = detect_context(input_text)
|
| 101 |
|
| 102 |
# Step 3: Print the list of high-confidence contexts
|
| 103 |
-
print("
|
| 104 |
|
| 105 |
# Return the translation and contexts
|
| 106 |
return translation, context_results
|
|
@@ -109,9 +109,9 @@ def process_request(input_text):
|
|
| 109 |
def gradio_interface(input_text):
|
| 110 |
translation, contexts = process_request(input_text)
|
| 111 |
# Format the output
|
| 112 |
-
output = f"Translation: {translation}\n\
|
| 113 |
-
for context
|
| 114 |
-
output += f"- {context}
|
| 115 |
return output.strip()
|
| 116 |
|
| 117 |
# Create the Gradio interface
|
|
@@ -120,7 +120,7 @@ interface = gr.Interface(
|
|
| 120 |
inputs="text",
|
| 121 |
outputs="text",
|
| 122 |
title="Frenchizer",
|
| 123 |
-
description="Translate text from English to French with context detection."
|
| 124 |
)
|
| 125 |
|
| 126 |
interface.launch()
|
|
|
|
| 60 |
return exp_x / exp_x.sum()
|
| 61 |
|
| 62 |
# Function to detect context
|
| 63 |
+
def detect_context(input_text, threshold=0.0275):
|
| 64 |
# Encode the input text
|
| 65 |
inputs = tokenizer([input_text], padding=True, truncation=True, return_tensors="pt")
|
| 66 |
with torch.no_grad():
|
|
|
|
| 100 |
context_results = detect_context(input_text)
|
| 101 |
|
| 102 |
# Step 3: Print the list of high-confidence contexts
|
| 103 |
+
print("Contexts:", context_results)
|
| 104 |
|
| 105 |
# Return the translation and contexts
|
| 106 |
return translation, context_results
|
|
|
|
| 109 |
def gradio_interface(input_text):
|
| 110 |
translation, contexts = process_request(input_text)
|
| 111 |
# Format the output
|
| 112 |
+
output = f"Translation: {translation}\n\nContexts:\n"
|
| 113 |
+
for context in contexts:
|
| 114 |
+
output += f"- {context}\n"
|
| 115 |
return output.strip()
|
| 116 |
|
| 117 |
# Create the Gradio interface
|
|
|
|
| 120 |
inputs="text",
|
| 121 |
outputs="text",
|
| 122 |
title="Frenchizer",
|
| 123 |
+
description="Translate text from English to French with context detection and threshold."
|
| 124 |
)
|
| 125 |
|
| 126 |
interface.launch()
|