zinoubm commited on
Commit
bed92b7
·
1 Parent(s): d11d97f

removing heroku conf

Browse files
.gitignore CHANGED
@@ -6,6 +6,8 @@ __pycache__/
6
  # C extensions
7
  *.so
8
 
 
 
9
  # Distribution / packaging
10
  .Python
11
  build/
 
6
  # C extensions
7
  *.so
8
 
9
+ .pip_cache/
10
+
11
  # Distribution / packaging
12
  .Python
13
  build/
app.py DELETED
@@ -1,46 +0,0 @@
1
- import gradio as gr
2
- import random
3
- import string
4
- import requests
5
-
6
-
7
- def get_random_string(length=6):
8
- letters = string.ascii_lowercase
9
- result_str = "".join(random.choice(letters) for i in range(length))
10
- return result_str
11
-
12
-
13
- def get_answer(question):
14
- try:
15
- answer = requests.get(
16
- "http://127.0.0.1:8000/api/",
17
- json={"question": question},
18
- )
19
- except Exception as err:
20
- return f"Sorry there was a problem with {err}, please check your connection and try again."
21
-
22
- if answer.status_code == 200:
23
- return answer.json()["answer"]
24
-
25
- return "Sorry, We have a problem with our server"
26
-
27
-
28
- def predict(input, history=[]):
29
- answer = get_answer(input)
30
- history.append((input, answer))
31
- response = history
32
- return response, history
33
-
34
-
35
- with gr.Blocks() as demo:
36
- chatbot = gr.Chatbot()
37
- state = gr.State([])
38
-
39
- with gr.Row():
40
- txt = gr.Textbox(
41
- show_label=False, placeholder="Enter text and press enter"
42
- ).style(container=False)
43
-
44
- txt.submit(predict, [txt, state], [chatbot, state])
45
-
46
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
backend/TwitterChatBot/__init__.py ADDED
File without changes
backend/backend/settings.py CHANGED
@@ -25,7 +25,7 @@ SECRET_KEY = "django-insecure-@0lshx3*e(q@2&#xaolq=%ak0-)-%_!xux^a&70@p1=x_o^(=g
25
  # SECURITY WARNING: don't run with debug turned on in production!
26
  DEBUG = True
27
 
28
- ALLOWED_HOSTS = []
29
 
30
 
31
  # Application definition
@@ -39,9 +39,11 @@ INSTALLED_APPS = [
39
  "django.contrib.staticfiles",
40
  "rest_framework",
41
  "chatbot",
 
42
  ]
43
 
44
  MIDDLEWARE = [
 
45
  "django.middleware.security.SecurityMiddleware",
46
  "django.contrib.sessions.middleware.SessionMiddleware",
47
  "django.middleware.common.CommonMiddleware",
@@ -51,6 +53,7 @@ MIDDLEWARE = [
51
  "django.middleware.clickjacking.XFrameOptionsMiddleware",
52
  ]
53
 
 
54
  ROOT_URLCONF = "backend.urls"
55
 
56
  TEMPLATES = [
@@ -123,3 +126,11 @@ STATIC_URL = "static/"
123
  # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
124
 
125
  DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
 
 
 
 
 
 
 
 
 
25
  # SECURITY WARNING: don't run with debug turned on in production!
26
  DEBUG = True
27
 
28
+ ALLOWED_HOSTS = ["0.0.0.0", "127.0.0.1"]
29
 
30
 
31
  # Application definition
 
39
  "django.contrib.staticfiles",
40
  "rest_framework",
41
  "chatbot",
42
+ "corsheaders",
43
  ]
44
 
45
  MIDDLEWARE = [
46
+ "corsheaders.middleware.CorsMiddleware",
47
  "django.middleware.security.SecurityMiddleware",
48
  "django.contrib.sessions.middleware.SessionMiddleware",
49
  "django.middleware.common.CommonMiddleware",
 
53
  "django.middleware.clickjacking.XFrameOptionsMiddleware",
54
  ]
55
 
56
+
57
  ROOT_URLCONF = "backend.urls"
58
 
59
  TEMPLATES = [
 
126
  # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
127
 
128
  DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
129
+
130
+
131
+ # Cors origin settings
132
+ CORS_ORIGIN_ALLOW_ALL = True
133
+
134
+ CORS_ORIGIN_WHITELIST = [
135
+ "http://localhost:3000",
136
+ ]
backend/chatbot/views.py CHANGED
@@ -9,6 +9,7 @@ class AskChatBot(APIView):
9
  """
10
 
11
  def get(self, request, format=None):
 
12
  question = request.data["question"]
13
  answer = ask(question=question)
14
 
 
9
  """
10
 
11
  def get(self, request, format=None):
12
+ print("working")
13
  question = request.data["question"]
14
  answer = ask(question=question)
15
 
dockerfile ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.8.13
2
+
3
+ ENV OPENAI_API_KEY = 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
4
+
5
+ # install nginx
6
+ RUN apt-get update && apt-get install nginx vim -y --no-install-recommends
7
+ COPY nginx.conf /etc/nginx/sites-available/default
8
+ RUN ln -sf /dev/stdout /var/log/nginx/access.log \
9
+ && ln -sf /dev/stderr /var/log/nginx/error.log
10
+
11
+ # copy source and install dependencies
12
+ RUN mkdir -p /opt/app
13
+ RUN mkdir -p /opt/app/pip_cache
14
+ RUN mkdir -p /opt/app/backend
15
+ COPY requirements.txt start-server.sh /opt/app/
16
+ COPY .pip_cache /opt/app/pip_cache/
17
+ COPY backend /opt/app/backend/
18
+ WORKDIR /opt/app
19
+ RUN pip install -r requirements.txt --cache-dir /opt/app/pip_cache
20
+ RUN chown -R www-data:www-data /opt/app
21
+
22
+ # start server
23
+ EXPOSE 8020
24
+ STOPSIGNAL SIGTERM
25
+ CMD ["/opt/app/start-server.sh"]
heroku.yml DELETED
@@ -1,3 +0,0 @@
1
- build:
2
- docker:
3
- web: Dockerfile
 
 
 
 
nginx.conf ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # nginx.default
2
+
3
+ server {
4
+ listen 8020;
5
+ server_name example.org;
6
+
7
+ location / {
8
+ proxy_pass http://127.0.0.1:8010;
9
+ proxy_set_header Host $host;
10
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
11
+ }
12
+ location /static {
13
+ root /opt/app/backend;
14
+ }
15
+ }
start-server.sh ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # start-server.sh
3
+ if [ -n "$DJANGO_SUPERUSER_USERNAME" ] && [ -n "$DJANGO_SUPERUSER_PASSWORD" ] ; then
4
+ (cd backend; python manage.py createsuperuser --no-input)
5
+ fi
6
+ (cd backend; gunicorn backend.wsgi --user www-data --bind 0.0.0.0:8010 --workers 3) &
7
+ nginx -g "daemon off;"