rishi1985 commited on
Commit
ca7aeda
1 Parent(s): d06e94c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -58
app.py CHANGED
@@ -1,79 +1,121 @@
1
- # Use the official Python 3.9 image as the base image
2
- FROM python:3.9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- # Expose the port
5
- EXPOSE 7860
6
 
7
- # Keeps Python from generating .pyc files in the container
8
- ENV PYTHONDONTWRITEBYTECODE=1
9
 
10
- # Turns off buffering for easier container logging
11
- ENV PYTHONUNBUFFERED=1
12
 
13
- # Set the PYNGROK_CONFIG environment variable
14
- ENV PYNGROK_CONFIG /tmp/pyngrok.yml
 
15
 
16
- # Set the NGROK_PATH environment variable to a writable location
17
- ENV NGROK_PATH /tmp/ngrok
18
 
19
- # Copy requirements.txt into the container
20
- COPY requirements.txt .
21
 
22
- # Upgrade pip and install the required packages
23
- RUN pip install --upgrade pip && \
24
- pip install -r requirements.txt
25
 
26
- # Install sudo and create the necessary directories before copying the files
27
- RUN apt-get update && \
28
- apt-get install -y sudo && \
29
- mkdir -p /code/image
30
 
31
- # Creates a non-root user with an explicit UID and adds permission to access the /code folder
32
- RUN adduser -u 5678 --disabled-password --gecos "" appuser && \
33
- usermod -aG sudo appuser && \
34
- usermod -aG root appuser && \
35
- chown -R appuser:appuser /code
36
 
37
- # Create the pyngrok bin directory and set the ownership and permissions for appuser
38
- RUN mkdir -p /usr/local/lib/python3.9/site-packages/pyngrok/bin && \
39
- chown -R appuser:appuser /usr/local/lib/python3.9/site-packages/pyngrok/bin && \
40
- chmod -R 777 /usr/local/lib/python3.9/site-packages/pyngrok/bin
41
 
42
- RUN mkdir -p /.ngrok2 && \
43
- chown -R appuser:appuser /.ngrok2 && \
44
- chmod -R 777 /.ngrok2
 
45
 
46
- RUN apt-get update && \
47
- apt-get install -y curl
48
 
49
- # Set the working directory and copy the files
50
- WORKDIR /code
51
 
52
- # Set the ownership and permissions for the /code directory and its contents
53
- RUN chown -R appuser:appuser /code && \
54
- chmod -R 777 /code
55
 
56
- COPY . /code
 
 
57
 
58
- # RUN chown -R appuser:appuser /code/data.csv && \
59
- # chmod -R 777 /code/data.csv
60
 
61
- # Copy the pyngrok.yml configuration file
62
- COPY pyngrok.yml /tmp/pyngrok.yml
63
 
64
- # Set the TRANSFORMERS_CACHE environment variable to a cache directory inside /tmp
65
- ENV TRANSFORMERS_CACHE /tmp/transformers_cache
66
- ENV TORCH_HOME /tmp/torch_cache
 
 
 
 
67
 
68
- USER appuser
69
 
70
- # Start the application using pyngrok
71
- # CMD python main.py
72
- # Get the public IP address and display it
73
- RUN curl -s https://api.ipify.org | xargs echo "Public IP:"
74
- RUN pip install gunicorn
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
- # Start the Uvicorn server
77
- # ENTRYPOINT ["python", "main.py"]
78
- # CMD ["sh", "-c", "python main.py & sleep infinity"]
79
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860","--workers","2"]
 
1
+ # import firebase_admin
2
+ # from firebase_admin import credentials
3
+ # from firebase_admin import firestore
4
+ import io
5
+ from fastapi import FastAPI, File, UploadFile
6
+ # from werkzeug.utils import secure_filename
7
+ # import speech_recognition as sr
8
+ import subprocess
9
+ import os
10
+ import requests
11
+ import random
12
+ import pandas as pd
13
+ # from pydub import AudioSegment
14
+ from datetime import datetime
15
+ from datetime import date
16
+ # import numpy as np
17
+ # from sklearn.ensemble import RandomForestRegressor
18
+ # import shutil
19
+ import json
20
+ # from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
21
+ from pydantic import BaseModel
22
+ from typing import Annotated
23
+ # from transformers import BertTokenizerFast, EncoderDecoderModel
24
+ import torch
25
+ import re
26
+ # from transformers import AutoTokenizer, T5ForConditionalGeneration
27
+ from fastapi import Form
28
+ # from transformers import AutoModelForSequenceClassification
29
+ # from transformers import TFAutoModelForSequenceClassification
30
+ # from transformers import AutoTokenizer, AutoConfig
31
+ # import numpy as np
32
+ # from scipy.special import softmax
33
+ from sentence_transformers import SentenceTransformer
34
 
 
 
35
 
 
 
36
 
 
 
37
 
38
+ # model = SentenceTransformer('flax-sentence-embeddings/all_datasets_v4_MiniLM-L6')
39
+ # model = SentenceTransformer("sentence-transformers/all-roberta-large-v1")
40
+ # model =SentenceTransformer("intfloat/multilingual-e5-large")
41
 
 
 
42
 
43
+ model = SentenceTransformer('intfloat/multilingual-e5-large')
 
44
 
 
 
 
45
 
46
+ class Query(BaseModel):
47
+ text: str
 
 
48
 
49
+
 
 
 
 
50
 
 
 
 
 
51
 
52
+ from fastapi import FastAPI, Request, Depends, UploadFile, File
53
+ from fastapi.exceptions import HTTPException
54
+ from fastapi.middleware.cors import CORSMiddleware
55
+ from fastapi.responses import JSONResponse
56
 
 
 
57
 
58
+ # now = datetime.now()
 
59
 
 
 
 
60
 
61
+ # UPLOAD_FOLDER = '/files'
62
+ # ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png',
63
+ # 'jpg', 'jpeg', 'gif', 'ogg', 'mp3', 'wav'}
64
 
 
 
65
 
66
+ app = FastAPI()
 
67
 
68
+ app.add_middleware(
69
+ CORSMiddleware,
70
+ allow_origins=['*'],
71
+ allow_credentials=True,
72
+ allow_methods=['*'],
73
+ allow_headers=['*'],
74
+ )
75
 
 
76
 
77
+ # cred = credentials.Certificate('key.json')
78
+ # app1 = firebase_admin.initialize_app(cred)
79
+ # db = firestore.client()
80
+ # data_frame = pd.read_csv('data.csv')
81
+
82
+
83
+
84
+ @app.on_event("startup")
85
+ async def startup_event():
86
+ print("on startup")
87
+
88
+
89
+
90
+
91
+ @app.post("/")
92
+ async def get_answer(q: Query ):
93
+
94
+ text = q.text
95
+ # text_e = model.encode(text)
96
+ input_texts = [text]
97
+ embeddings = model.encode(input_texts)
98
+ text_e = embeddings[0]
99
+
100
+
101
+ dict={ }
102
+
103
+ c=0
104
+ text_e= text_e.tolist()
105
+
106
+ for num in text_e:
107
+ dict[c]= num
108
+ c= c+1
109
+
110
+
111
+
112
+ return dict
113
+
114
+
115
+
116
+
117
+
118
+ return "hello"
119
+
120
+
121