MarkChenX commited on
Commit
2348002
Β·
1 Parent(s): 0dca08c

update codebase

Browse files
Dockerfile ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the custom FastAPI image
2
+ # FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
3
+ # Use ubuntu as base image
4
+ FROM ubuntu:20.04
5
+
6
+ # Avoid prompts from apt
7
+ ENV DEBIAN_FRONTEND=noninteractive
8
+
9
+ # Update apt repositories and install Python and Pip
10
+ RUN apt-get update && \
11
+ apt-get install -y python3-pip python3-dev
12
+
13
+ # Check if the symbolic links already exist and create them if they don't
14
+ RUN if [ ! -e /usr/bin/python ]; then ln -s /usr/bin/python3 /usr/bin/python; fi && \
15
+ if [ ! -e /usr/bin/pip ]; then ln -s /usr/bin/pip3 /usr/bin/pip; fi
16
+
17
+ # Set default values for environment variables
18
+ ENV OPENAI_ORG_ID=default_org_id
19
+ ENV OPENAI_API_KEY=default_api_key
20
+ ENV HUGGINGFACE_API_TOKEN=default_huggingface_token
21
+
22
+ # Set environment variables for Matplotlib and Fontconfig
23
+ ENV MPLCONFIGDIR=/app/matplotlib_cache
24
+ ENV FONTCONFIG_PATH=/app/fontconfig
25
+
26
+ # Create the directories for Matplotlib cache and Fontconfig
27
+ RUN mkdir -p /app/matplotlib_cache /app/fontconfig && \
28
+ chmod -R 777 /app/matplotlib_cache /app/fontconfig
29
+
30
+ # Create a writable directory for Fontconfig cache
31
+ RUN mkdir -p /app/fontconfig_cache && chmod -R 777 /app/fontconfig_cache
32
+
33
+ # Set the environment variable so Fontconfig uses the writable directory
34
+ ENV FONTCONFIG_PATH=/app/fontconfig_cache
35
+
36
+ # Copy the requirements file and install dependencies
37
+ COPY ./requirements.txt /code/requirements.txt
38
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
39
+
40
+ # Copy your application source code and script
41
+ COPY ./api /app
42
+
43
+ CMD ["uvicorn", "app.app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app/__init__.py β†’ __init__.py RENAMED
File without changes
{app/ai β†’ ai copy}/__init__.py RENAMED
File without changes
{app/ai β†’ ai copy}/chatbot.py RENAMED
File without changes
ai/__init__.py ADDED
File without changes
ai/chatbot.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from openai import OpenAI
3
+ import requests
4
+
5
+ API_TOKEN = os.getenv("HUGGINGFACE_API_TOKEN")
6
+
7
+ API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf"
8
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
9
+
10
+ client = OpenAI(
11
+ organization=os.getenv("OPENAI_ORG_ID"), api_key=os.getenv("OPENAI_API_KEY")
12
+ )
13
+
14
+
15
+ def gpt_chatbot(user_request: str):
16
+ completion = client.chat.completions.create(
17
+ model="gpt-4o-mini",
18
+ messages=[
19
+ {"role": "system", "content": "You are a helpful assistant."},
20
+ {"role": "user", "content": user_request},
21
+ ],
22
+ )
23
+
24
+ return completion.choices[0].message.content
25
+
26
+
27
+ def llama_chatbot(user_request: str):
28
+ response = requests.post(API_URL, headers=headers, json={"inputs": user_request})
29
+
30
+ return response.json()[0]["generated_text"]
app/main.py β†’ main.py RENAMED
File without changes