saikub commited on
Commit
e4b1cae
·
verified ·
1 Parent(s): 378b7f7

Update run_app.py

Browse files
Files changed (1) hide show
  1. run_app.py +33 -25
run_app.py CHANGED
@@ -1,32 +1,40 @@
1
- import gradio as gr
2
- from gradio_auth import Auth
3
  import subprocess
 
4
 
5
- # Define your username and password
6
- USERNAME = "your_username"
7
- PASSWORD = "your_password"
8
 
9
- # Create an authentication object
10
- auth = Auth((USERNAME, PASSWORD))
 
11
 
12
- # Define a dummy function to initiate Gradio
13
- def dummy_function(input_text):
14
- return "Authentication successful. Starting the app..."
 
 
 
 
 
 
 
15
 
16
- # Create a Gradio interface with authentication
17
- iface = gr.Interface(
18
- fn=dummy_function,
19
- inputs="text",
20
- outputs="text",
21
- auth=auth
22
- )
 
23
 
24
- # Launch the dummy interface to handle authentication
25
- iface.launch(
26
- server_name="0.0.0.0",
27
- server_port=7860,
28
- prevent_thread_lock=True
29
- )
30
 
31
- # After successful authentication, run the actual app
32
- subprocess.run(["python", "app_w_lora.py"])
 
 
 
 
 
1
+ from flask import Flask, request, redirect, url_for, render_template_string
 
2
  import subprocess
3
+ import threading
4
 
5
+ app = Flask(__name__)
 
 
6
 
7
+ # Replace these with your desired username and password
8
+ USERNAME = 'your_username'
9
+ PASSWORD = 'your_password'
10
 
11
+ html_login = '''
12
+ <!doctype html>
13
+ <title>Login</title>
14
+ <h1>Login</h1>
15
+ <form method=post>
16
+ <input type=text name=username placeholder='Username'>
17
+ <input type=password name=password placeholder='Password'>
18
+ <input type=submit value=Login>
19
+ </form>
20
+ '''
21
 
22
+ @app.route('/', methods=['GET', 'POST'])
23
+ def login():
24
+ if request.method == 'POST':
25
+ if request.form['username'] == USERNAME and request.form['password'] == PASSWORD:
26
+ return redirect(url_for('gradio_app'))
27
+ else:
28
+ return 'Incorrect credentials', 401
29
+ return render_template_string(html_login)
30
 
31
+ @app.route('/gradio')
32
+ def gradio_app():
33
+ return redirect("http://localhost:7860")
 
 
 
34
 
35
+ def run_gradio():
36
+ subprocess.run(["python", "app_w_lora.py"])
37
+
38
+ if __name__ == "__main__":
39
+ threading.Thread(target=run_gradio).start()
40
+ app.run(host='0.0.0.0', port=5000)