sashtech commited on
Commit
d0142da
·
verified ·
1 Parent(s): 08f688c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import os
4
+ import language_tool_python
5
+
6
+ # Function to call the Java method
7
+ def call_java_method(input_text):
8
+ # Here you can call your Java application.
9
+ # Example: Adjust this line to your actual Java application call.
10
+ try:
11
+ result = subprocess.run(
12
+ ["java", "-jar", "YourJavaApp.jar", input_text],
13
+ capture_output=True,
14
+ text=True,
15
+ check=True
16
+ )
17
+ return result.stdout.strip() # Return the output from the Java application
18
+ except subprocess.CalledProcessError as e:
19
+ return f"Error: {e}"
20
+
21
+ # Function to correct grammar using LanguageTool
22
+ def correct_grammar(text):
23
+ tool = language_tool_python.LanguageTool('en-US')
24
+ matches = tool.check(text)
25
+ corrected_text = language_tool_python.utils.correct(text, matches)
26
+ return corrected_text
27
+
28
+ # Function to process input text
29
+ def process_text(input_text):
30
+ java_output = call_java_method(input_text)
31
+ corrected_output = correct_grammar(java_output)
32
+ return corrected_output
33
+
34
+ # Gradio interface
35
+ iface = gr.Interface(
36
+ fn=process_text,
37
+ inputs="text",
38
+ outputs="text",
39
+ title="Text Processing App",
40
+ description="Enter text to process it through Java and correct grammar using LanguageTool."
41
+ )
42
+
43
+ if __name__ == "__main__":
44
+ iface.launch(share=True)