Spaces:
No application file
No application file
removing heroku conf
Browse filesFiles changed (9)
- .gitignore+2
- app.pyDeleted-46
- backend/TwitterChatBot/__init__.pyAdded
- backend/backend/settings.py+12-1
- backend/chatbot/views.py+1
- dockerfileAdded+25
- heroku.ymlDeleted-3
- nginx.confAdded+15
- start-server.shAdded+7
5 unmodified lines678910115 unmodified lines# C extensions*.so# Distribution / packaging.Pythonbuild/5 unmodified lines6789101112135 unmodified lines# C extensions*.so.pip_cache/# Distribution / packaging.Pythonbuild/
12345678910111213141516171819202122232425262728293031323334353637383940414243444546import gradio as grimport randomimport stringimport requests
def get_random_string(length=6): letters = string.ascii_lowercase result_str = "".join(random.choice(letters) for i in range(length)) return result_str
def get_answer(question): try: answer = requests.get( "http://127.0.0.1:8000/api/", json={"question": question}, ) except Exception as err: return f"Sorry there was a problem with {err}, please check your connection and try again."
if answer.status_code == 200: return answer.json()["answer"]
return "Sorry, We have a problem with our server"
def predict(input, history=[]): answer = get_answer(input) history.append((input, answer)) response = history return response, history
with gr.Blocks() as demo: chatbot = gr.Chatbot() state = gr.State([])
with gr.Row(): txt = gr.Textbox( show_label=False, placeholder="Enter text and press enter" ).style(container=False)
txt.submit(predict, [txt, state], [chatbot, state])
demo.launch()24 unmodified lines252627282930317 unmodified lines3940414243444546473 unmodified lines51525354555666 unmodified lines12312412524 unmodified lines# SECURITY WARNING: don't run with debug turned on in production!DEBUG = TrueALLOWED_HOSTS = []# Application definition7 unmodified lines"django.contrib.staticfiles","rest_framework","chatbot",]MIDDLEWARE = ["django.middleware.security.SecurityMiddleware","django.contrib.sessions.middleware.SessionMiddleware","django.middleware.common.CommonMiddleware",3 unmodified lines"django.middleware.clickjacking.XFrameOptionsMiddleware",]ROOT_URLCONF = "backend.urls"TEMPLATES = [66 unmodified lines# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-fieldDEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"24 unmodified lines252627282930317 unmodified lines39404142434445464748493 unmodified lines5354555657585966 unmodified lines12612712812913013113213313413513624 unmodified lines# SECURITY WARNING: don't run with debug turned on in production!DEBUG = TrueALLOWED_HOSTS = ["0.0.0.0", "127.0.0.1"]# Application definition7 unmodified lines"django.contrib.staticfiles","rest_framework","chatbot","corsheaders",]MIDDLEWARE = ["corsheaders.middleware.CorsMiddleware","django.middleware.security.SecurityMiddleware","django.contrib.sessions.middleware.SessionMiddleware","django.middleware.common.CommonMiddleware",3 unmodified lines"django.middleware.clickjacking.XFrameOptionsMiddleware",]ROOT_URLCONF = "backend.urls"TEMPLATES = [66 unmodified lines# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-fieldDEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"# Cors origin settingsCORS_ORIGIN_ALLOW_ALL = TrueCORS_ORIGIN_WHITELIST = ["http://localhost:3000",]
8 unmodified lines910111213148 unmodified lines"""def get(self, request, format=None):question = request.data["question"]answer = ask(question=question)8 unmodified lines91011121314158 unmodified lines"""def get(self, request, format=None):print("working")question = request.data["question"]answer = ask(question=question)
12345678910111213141516171819202122232425FROM python:3.8.13
ENV OPENAI_API_KEY = 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
# install nginxRUN apt-get update && apt-get install nginx vim -y --no-install-recommendsCOPY nginx.conf /etc/nginx/sites-available/defaultRUN ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log
# copy source and install dependenciesRUN mkdir -p /opt/appRUN mkdir -p /opt/app/pip_cacheRUN mkdir -p /opt/app/backendCOPY requirements.txt start-server.sh /opt/app/COPY .pip_cache /opt/app/pip_cache/COPY backend /opt/app/backend/WORKDIR /opt/appRUN pip install -r requirements.txt --cache-dir /opt/app/pip_cacheRUN chown -R www-data:www-data /opt/app
# start serverEXPOSE 8020STOPSIGNAL SIGTERMCMD ["/opt/app/start-server.sh"]123build: docker: web: Dockerfile123456789101112131415# nginx.default
server { listen 8020; server_name example.org;
location / { proxy_pass http://127.0.0.1:8010; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /static { root /opt/app/backend; }}1234567#!/usr/bin/env bash# start-server.shif [ -n "$DJANGO_SUPERUSER_USERNAME" ] && [ -n "$DJANGO_SUPERUSER_PASSWORD" ] ; then (cd backend; python manage.py createsuperuser --no-input)fi(cd backend; gunicorn backend.wsgi --user www-data --bind 0.0.0.0:8010 --workers 3) &nginx -g "daemon off;".gitignore+2
app.pyDeleted-46
backend/TwitterChatBot/__init__.pyAdded
backend/backend/settings.py+12-1
backend/chatbot/views.py+1
dockerfileAdded+25
heroku.ymlDeleted-3
nginx.confAdded+15
start-server.shAdded+7