Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -96,6 +96,29 @@ def save_as_pdf(text, output_path):
|
|
96 |
except Exception as e:
|
97 |
return f"Error saving PDF: {str(e)}"
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
# Translation function
|
100 |
def translate(text, source_lang, target_lang, max_length=1024):
|
101 |
"""Translate text from source language to target language"""
|
@@ -169,7 +192,7 @@ def process_file(file, source_lang, target_lang):
|
|
169 |
except Exception as e:
|
170 |
return None, f"Error processing file: {str(e)}"
|
171 |
|
172 |
-
# Create Gradio
|
173 |
with gr.Blocks(title="Indian Language Translator") as demo:
|
174 |
gr.Markdown("# Indian & Global Language Translator")
|
175 |
gr.Markdown("Translate text with understanding of idioms and cultural expressions")
|
@@ -213,6 +236,5 @@ with gr.Blocks(title="Indian Language Translator") as demo:
|
|
213 |
gr.Markdown("- Context-aware translation that understands idioms and cultural expressions")
|
214 |
gr.Markdown("- Document translation with PDF output")
|
215 |
|
216 |
-
# Launch the interface
|
217 |
if __name__ == "__main__":
|
218 |
demo.launch(share=True)
|
|
|
96 |
except Exception as e:
|
97 |
return f"Error saving PDF: {str(e)}"
|
98 |
|
99 |
+
def get_type(schema: dict | bool):
|
100 |
+
"""Updated get_type function to handle boolean schemas"""
|
101 |
+
if isinstance(schema, bool):
|
102 |
+
return "boolean"
|
103 |
+
if "const" in schema:
|
104 |
+
return "const"
|
105 |
+
if "enum" in schema:
|
106 |
+
return "enum"
|
107 |
+
elif "type" in schema:
|
108 |
+
return schema["type"]
|
109 |
+
elif schema.get("$ref"):
|
110 |
+
return "$ref"
|
111 |
+
elif schema.get("oneOf"):
|
112 |
+
return "oneOf"
|
113 |
+
elif schema.get("anyOf"):
|
114 |
+
return "anyOf"
|
115 |
+
elif schema.get("allOf"):
|
116 |
+
return "allOf"
|
117 |
+
elif "type" not in schema:
|
118 |
+
return {}
|
119 |
+
else:
|
120 |
+
raise ValueError(f"Cannot parse type for {schema}")
|
121 |
+
|
122 |
# Translation function
|
123 |
def translate(text, source_lang, target_lang, max_length=1024):
|
124 |
"""Translate text from source language to target language"""
|
|
|
192 |
except Exception as e:
|
193 |
return None, f"Error processing file: {str(e)}"
|
194 |
|
195 |
+
# Create Gradio interface
|
196 |
with gr.Blocks(title="Indian Language Translator") as demo:
|
197 |
gr.Markdown("# Indian & Global Language Translator")
|
198 |
gr.Markdown("Translate text with understanding of idioms and cultural expressions")
|
|
|
236 |
gr.Markdown("- Context-aware translation that understands idioms and cultural expressions")
|
237 |
gr.Markdown("- Document translation with PDF output")
|
238 |
|
|
|
239 |
if __name__ == "__main__":
|
240 |
demo.launch(share=True)
|