Update app.py
Browse files
app.py
CHANGED
@@ -40,14 +40,23 @@ parser = StrOutputParser()
|
|
40 |
# 4. Create chain
|
41 |
chain = prompt_template | llm | parser
|
42 |
|
43 |
-
def translate(text,
|
|
|
44 |
input_data = {
|
45 |
-
"
|
46 |
-
"
|
|
|
47 |
}
|
48 |
# Use the .invoke() method to properly run the chain
|
49 |
result = chain.invoke(input_data)
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
# Gradio interface
|
53 |
iface = gr.Interface(
|
|
|
40 |
# 4. Create chain
|
41 |
chain = prompt_template | llm | parser
|
42 |
|
43 |
+
def translate(text, target_language):
|
44 |
+
source_language = "English" # Assuming the source language is English
|
45 |
input_data = {
|
46 |
+
"source_language": source_language,
|
47 |
+
"target_language": target_language,
|
48 |
+
"text": text
|
49 |
}
|
50 |
# Use the .invoke() method to properly run the chain
|
51 |
result = chain.invoke(input_data)
|
52 |
+
|
53 |
+
# Extract the translation from the result
|
54 |
+
if "Assistant: " in result:
|
55 |
+
translation = result.split("Assistant: ")[-1].strip()
|
56 |
+
else:
|
57 |
+
translation = result.strip()
|
58 |
+
|
59 |
+
return translation
|
60 |
|
61 |
# Gradio interface
|
62 |
iface = gr.Interface(
|