rajaramesh commited on
Commit
46da807
·
verified ·
1 Parent(s): be5adfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -12
app.py CHANGED
@@ -66,13 +66,43 @@ def terminal(command: str) -> str:
66
 
67
  Returns:
68
  The command output (stdout and stderr combined)
69
- """
70
- return (
71
- "# Hey you are accessing a dummy terminal. \n"
72
- "- Its very dangerous to exposing a terminal as a tool to public. \n"
73
- "- If you want this terminal tool working in action, then checkout my youtube video: "
74
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
 
 
 
 
 
 
 
76
 
77
 
78
  # Create multiple interfaces
@@ -81,6 +111,7 @@ text_extract_fn = gr.Interface(
81
  fn=text_extract,
82
  inputs=gr.Textbox(placeholder="Paste any website or youtube video url"),
83
  outputs=gr.Textbox(placeholder="Text extracted from website or youtube video"),
 
84
  title="Text Extractor",
85
  description="Extract the text from any website or youtube video."
86
  )
@@ -88,17 +119,35 @@ text_extract_fn = gr.Interface(
88
  terminal_fn = gr.Interface(
89
  fn=terminal,
90
  inputs=gr.Textbox(placeholder="Enter you command"),
91
- outputs="markdown",
92
  flagging_mode="never", # Disables the flag button
93
- title="Shell Server",
94
- description="Runs the shell commands on your computer."
 
 
 
 
 
 
 
 
95
  )
96
 
97
  # Combine using tabs
98
- demo = gr.TabbedInterface(
99
- [text_extract_fn, terminal_fn],
100
- ["Text Extractor", "Command Terminal"]
 
 
 
 
 
 
 
 
 
101
  )
 
102
 
103
  if __name__ == "__main__":
104
  demo.launch(mcp_server=True)
 
66
 
67
  Returns:
68
  The command output (stdout and stderr combined)
69
+ """
70
+ try:
71
+ # Run the command and capture output
72
+ result = subprocess.run(
73
+ command,
74
+ shell=True,
75
+ check=False,
76
+ stdout=subprocess.PIPE,
77
+ stderr=subprocess.PIPE,
78
+ text=True
79
+ )
80
+
81
+ # Combine stdout and stderr
82
+ output = result.stdout
83
+ if result.stderr:
84
+ output += "\n" + result.stderr
85
+
86
+ return output
87
+ except Exception as e:
88
+ return f"Error executing command: {str(e)}"
89
+
90
+
91
+ import gradio as gr
92
+
93
+ def generate_file(content: str) -> str:
94
+ """Generates a downloadable text file with the specified content.
95
+
96
+ Args:
97
+ content (str): The text to be written into the file.
98
 
99
+ Returns:
100
+ str: The file path for downloading.
101
+ """
102
+ file_path = "sample.txt" # Ensuring a .txt extension
103
+ with open(file_path, "w", encoding="utf-8") as f:
104
+ f.write(content)
105
+ return file_path # Returning the file path for download
106
 
107
 
108
  # Create multiple interfaces
 
111
  fn=text_extract,
112
  inputs=gr.Textbox(placeholder="Paste any website or youtube video url"),
113
  outputs=gr.Textbox(placeholder="Text extracted from website or youtube video"),
114
+ flagging_mode="never", # Disables the flag button
115
  title="Text Extractor",
116
  description="Extract the text from any website or youtube video."
117
  )
 
119
  terminal_fn = gr.Interface(
120
  fn=terminal,
121
  inputs=gr.Textbox(placeholder="Enter you command"),
122
+ outputs=gr.Textbox(placeholder="Command output"),
123
  flagging_mode="never", # Disables the flag button
124
+ title="Command Prompt",
125
+ description="Runs the terminal commands on your computer."
126
+ )
127
+
128
+ generate_file_fn = gr.Interface(
129
+ fn=generate_file,
130
+ inputs=gr.Textbox(label="File Content", placeholder="Enter text to save in file"),
131
+ outputs=gr.File(label="Download your file"),
132
+ title="Text File Generator",
133
+ description="Create and download a file with your custom content."
134
  )
135
 
136
  # Combine using tabs
137
+ with gr.Blocks() as demo:(
138
+ gr.Markdown("# Please checkout below video to know about this Gradio MCP Server"),
139
+ gr.HTML(
140
+ """<iframe width="560" height="315"
141
+ src="https://www.youtube.com/embed/4_O3-jjQExQ"
142
+ frameborder="0" allowfullscreen></iframe>""",
143
+ label="Featured Video"
144
+ ),
145
+ gr.TabbedInterface(
146
+ [text_extract_fn, terminal_fn, generate_file_fn],
147
+ ["Text Extractor", "Command Prompt", "File Generator"]
148
+ )
149
  )
150
+
151
 
152
  if __name__ == "__main__":
153
  demo.launch(mcp_server=True)