add initial files
Browse files- Dockerfile +11 -0
- README.md +5 -5
- app/start.sh +18 -0
- app/websocket.py +61 -0
- app/whisper.py +10 -0
- default +102 -0
- requirements.txt +5 -0
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
WORKDIR /fastapi/app
|
3 |
+
RUN apt-get update && apt-get install -y \
|
4 |
+
nginx \
|
5 |
+
&& rm -rf /var/lib/apt/lists/*
|
6 |
+
COPY ./requirements.txt /fastapi/requirements.txt
|
7 |
+
RUN pip install --no-cache-dir --upgrade -r /fastapi/requirements.txt
|
8 |
+
COPY ./app /fastapi/app
|
9 |
+
COPY ./default /etc/nginx/sites-available
|
10 |
+
EXPOSE 7860
|
11 |
+
CMD ["/bin/sh", "/fastapi/app/start.sh"]
|
README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
-
license:
|
9 |
---
|
10 |
|
11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Websocket
|
3 |
+
emoji: π
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: yellow
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
+
license: cc
|
9 |
---
|
10 |
|
11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app/start.sh
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env bash
|
2 |
+
set -e
|
3 |
+
|
4 |
+
cd /fastapi/app
|
5 |
+
|
6 |
+
nginx
|
7 |
+
|
8 |
+
python whisper.py&
|
9 |
+
|
10 |
+
if [ "$DEBUG" = true ] ; then
|
11 |
+
echo 'Debugging - ON'
|
12 |
+
uvicorn websocket:app --host 0.0.0.0 --port 7880 --reload
|
13 |
+
else
|
14 |
+
echo 'Debugging - OFF'
|
15 |
+
uvicorn websocket:app --host 0.0.0.0 --port 7880
|
16 |
+
echo $?
|
17 |
+
echo END
|
18 |
+
fi
|
app/websocket.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, WebSocket
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
import os
|
4 |
+
|
5 |
+
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
html = """
|
9 |
+
<!DOCTYPE html>
|
10 |
+
<html>
|
11 |
+
<head>
|
12 |
+
<title>Chat</title>
|
13 |
+
</head>
|
14 |
+
<body>
|
15 |
+
<h1>WebSocket Chat</h1>
|
16 |
+
<form action="" onsubmit="sendMessage(event)">
|
17 |
+
<input type="text" id="messageText" autocomplete="off"/>
|
18 |
+
<button>Send</button>
|
19 |
+
</form>
|
20 |
+
<ul id='messages'>
|
21 |
+
</ul>
|
22 |
+
<script>
|
23 |
+
var ws = new WebSocket("ws://localhost:8000/api/ws");
|
24 |
+
//var ws = new WebSocket("wss://cahya-websocket.hf.space/ws");
|
25 |
+
ws.onmessage = function(event) {
|
26 |
+
var messages = document.getElementById('messages')
|
27 |
+
var message = document.createElement('li')
|
28 |
+
var content = document.createTextNode(event.data)
|
29 |
+
message.appendChild(content)
|
30 |
+
messages.appendChild(message)
|
31 |
+
};
|
32 |
+
function sendMessage(event) {
|
33 |
+
var input = document.getElementById("messageText")
|
34 |
+
ws.send(input.value)
|
35 |
+
input.value = ''
|
36 |
+
event.preventDefault()
|
37 |
+
}
|
38 |
+
</script>
|
39 |
+
</body>
|
40 |
+
</html>
|
41 |
+
"""
|
42 |
+
|
43 |
+
|
44 |
+
@app.get("/")
|
45 |
+
async def get():
|
46 |
+
return HTMLResponse(html)
|
47 |
+
|
48 |
+
@app.get("/env")
|
49 |
+
async def env():
|
50 |
+
environment_variables = "<h3>Environment Variables</h3>"
|
51 |
+
for name, value in os.environ.items():
|
52 |
+
environment_variables += f"{name}: {value}<br>"
|
53 |
+
return HTMLResponse(environment_variables)
|
54 |
+
|
55 |
+
@app.websocket("/ws")
|
56 |
+
async def websocket_endpoint(websocket: WebSocket):
|
57 |
+
await websocket.accept()
|
58 |
+
while True:
|
59 |
+
data = await websocket.receive_text()
|
60 |
+
await websocket.send_text(f"Message text was: {data}")
|
61 |
+
|
app/whisper.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def greet(name):
|
5 |
+
return "Hello " + name + "!"
|
6 |
+
|
7 |
+
|
8 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
9 |
+
|
10 |
+
demo.launch(server_port=7870)
|
default
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
##
|
2 |
+
# You should look at the following URL's in order to grasp a solid understanding
|
3 |
+
# of Nginx configuration files in order to fully unleash the power of Nginx.
|
4 |
+
# https://www.nginx.com/resources/wiki/start/
|
5 |
+
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
|
6 |
+
# https://wiki.debian.org/Nginx/DirectoryStructure
|
7 |
+
#
|
8 |
+
# In most cases, administrators will remove this file from sites-enabled/ and
|
9 |
+
# leave it as reference inside of sites-available where it will continue to be
|
10 |
+
# updated by the nginx packaging team.
|
11 |
+
#
|
12 |
+
# This file will automatically load configuration files provided by other
|
13 |
+
# applications, such as Drupal or Wordpress. These applications will be made
|
14 |
+
# available underneath a path with that package name, such as /drupal8.
|
15 |
+
#
|
16 |
+
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
|
17 |
+
##
|
18 |
+
|
19 |
+
# Default server configuration
|
20 |
+
#
|
21 |
+
server {
|
22 |
+
listen 7860 default_server;
|
23 |
+
listen [::]:7860 default_server;
|
24 |
+
|
25 |
+
# SSL configuration
|
26 |
+
#
|
27 |
+
# listen 443 ssl default_server;
|
28 |
+
# listen [::]:443 ssl default_server;
|
29 |
+
#
|
30 |
+
# Note: You should disable gzip for SSL traffic.
|
31 |
+
# See: https://bugs.debian.org/773332
|
32 |
+
#
|
33 |
+
# Read up on ssl_ciphers to ensure a secure configuration.
|
34 |
+
# See: https://bugs.debian.org/765782
|
35 |
+
#
|
36 |
+
# Self signed certs generated by the ssl-cert package
|
37 |
+
# Don't use them in a production server!
|
38 |
+
#
|
39 |
+
# include snippets/snakeoil.conf;
|
40 |
+
|
41 |
+
root /var/www/html;
|
42 |
+
|
43 |
+
# Add index.php to the list if you are using PHP
|
44 |
+
index index.html index.htm index.nginx-debian.html;
|
45 |
+
|
46 |
+
server_name _;
|
47 |
+
|
48 |
+
location / {
|
49 |
+
proxy_set_header Host $host;
|
50 |
+
proxy_set_header X-Real-IP $remote_addr;
|
51 |
+
proxy_pass http://localhost:7870;
|
52 |
+
}
|
53 |
+
|
54 |
+
location /api/ {
|
55 |
+
proxy_set_header Host $host;
|
56 |
+
proxy_set_header X-Real-IP $remote_addr;
|
57 |
+
proxy_pass http://localhost:7880/;
|
58 |
+
|
59 |
+
proxy_http_version 1.1;
|
60 |
+
proxy_set_header Upgrade $http_upgrade;
|
61 |
+
proxy_set_header Connection "upgrade";
|
62 |
+
}
|
63 |
+
|
64 |
+
|
65 |
+
# pass PHP scripts to FastCGI server
|
66 |
+
#
|
67 |
+
#location ~ \.php$ {
|
68 |
+
# include snippets/fastcgi-php.conf;
|
69 |
+
#
|
70 |
+
# # With php-fpm (or other unix sockets):
|
71 |
+
# fastcgi_pass unix:/run/php/php7.4-fpm.sock;
|
72 |
+
# # With php-cgi (or other tcp sockets):
|
73 |
+
# fastcgi_pass 127.0.0.1:9000;
|
74 |
+
#}
|
75 |
+
|
76 |
+
# deny access to .htaccess files, if Apache's document root
|
77 |
+
# concurs with nginx's one
|
78 |
+
#
|
79 |
+
#location ~ /\.ht {
|
80 |
+
# deny all;
|
81 |
+
#}
|
82 |
+
}
|
83 |
+
|
84 |
+
|
85 |
+
# Virtual Host configuration for example.com
|
86 |
+
#
|
87 |
+
# You can move that to a different file under sites-available/ and symlink that
|
88 |
+
# to sites-enabled/ to enable it.
|
89 |
+
#
|
90 |
+
#server {
|
91 |
+
# listen 80;
|
92 |
+
# listen [::]:80;
|
93 |
+
#
|
94 |
+
# server_name example.com;
|
95 |
+
#
|
96 |
+
# root /var/www/example.com;
|
97 |
+
# index index.html;
|
98 |
+
#
|
99 |
+
# location / {
|
100 |
+
# try_files $uri $uri/ =404;
|
101 |
+
# }
|
102 |
+
#}
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
fastapi
|
3 |
+
pydantic
|
4 |
+
uvicorn
|
5 |
+
websockets
|