Spaces:
Sleeping
Sleeping
Added gemini pro
Browse files- .env +1 -0
- app.py +59 -28
- requirements.txt +127 -34
.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
GOOGLE_API_KEY="AIzaSyD5k4WkMPdP-SkmRgswFm-6OjqSv8U1_Zw"
|
app.py
CHANGED
|
@@ -10,15 +10,34 @@ import requests
|
|
| 10 |
from io import BytesIO
|
| 11 |
from bs4 import BeautifulSoup
|
| 12 |
from urllib.parse import urljoin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 15 |
|
| 16 |
app = Flask(__name__)
|
| 17 |
cors = CORS(app)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
model = AutoModelForImageClassification.from_pretrained('carbon225/vit-base-patch16-224-hentai')
|
| 21 |
-
feature_extractor = AutoFeatureExtractor.from_pretrained('carbon225/vit-base-patch16-224-hentai')
|
| 22 |
|
| 23 |
@app.route("/", methods=["GET"])
|
| 24 |
def default():
|
|
@@ -40,38 +59,50 @@ def extract_images():
|
|
| 40 |
except Exception as e:
|
| 41 |
return e
|
| 42 |
|
| 43 |
-
@app.route("/predict", methods=["GET"])
|
| 44 |
-
def predict():
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
if __name__ == "__main__":
|
| 77 |
app.run(debug=True)
|
|
|
|
| 10 |
from io import BytesIO
|
| 11 |
from bs4 import BeautifulSoup
|
| 12 |
from urllib.parse import urljoin
|
| 13 |
+
import google.generativeai as genai
|
| 14 |
+
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 15 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 16 |
+
import warnings
|
| 17 |
+
from dotenv import load_dotenv
|
| 18 |
|
| 19 |
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 20 |
|
| 21 |
app = Flask(__name__)
|
| 22 |
cors = CORS(app)
|
| 23 |
+
load_dotenv()
|
| 24 |
+
|
| 25 |
+
# # Define the model and feature extractor globally
|
| 26 |
+
# model = AutoModelForImageClassification.from_pretrained('carbon225/vit-base-patch16-224-hentai')
|
| 27 |
+
# feature_extractor = AutoFeatureExtractor.from_pretrained('carbon225/vit-base-patch16-224-hentai')
|
| 28 |
+
|
| 29 |
+
def load_model():
|
| 30 |
+
api_key=os.getenv("GOOGLE_API_KEY")
|
| 31 |
+
genai.configure(api_key=api_key)
|
| 32 |
+
model = ChatGoogleGenerativeAI(model="gemini-pro",
|
| 33 |
+
temperature=0.3)
|
| 34 |
+
|
| 35 |
+
return model
|
| 36 |
+
|
| 37 |
+
def load_embeddings():
|
| 38 |
+
embeddings = GoogleGenerativeAIEmbeddings(model = "models/embedding-001")
|
| 39 |
|
| 40 |
+
return embeddings
|
|
|
|
|
|
|
| 41 |
|
| 42 |
@app.route("/", methods=["GET"])
|
| 43 |
def default():
|
|
|
|
| 59 |
except Exception as e:
|
| 60 |
return e
|
| 61 |
|
| 62 |
+
# @app.route("/predict", methods=["GET"])
|
| 63 |
+
# def predict():
|
| 64 |
+
# try:
|
| 65 |
+
# src = request.args.get("src")
|
| 66 |
|
| 67 |
+
# # Download image from the provided URL
|
| 68 |
+
# response = requests.get(src)
|
| 69 |
+
# response.raise_for_status()
|
| 70 |
|
| 71 |
+
# # Open and preprocess the image
|
| 72 |
+
# image = Image.open(BytesIO(response.content))
|
| 73 |
+
# image = image.resize((128, 128))
|
| 74 |
|
| 75 |
+
# # Extract features using the pre-trained feature extractor
|
| 76 |
+
# encoding = feature_extractor(images=image.convert("RGB"), return_tensors="pt")
|
| 77 |
|
| 78 |
+
# # Make a prediction using the pre-trained model
|
| 79 |
+
# with torch.no_grad():
|
| 80 |
+
# outputs = model(**encoding)
|
| 81 |
+
# logits = outputs.logits
|
| 82 |
|
| 83 |
+
# # Get the predicted class index and label
|
| 84 |
+
# predicted_class_idx = logits.argmax(-1).item()
|
| 85 |
+
# predicted_class_label = model.config.id2label[predicted_class_idx]
|
| 86 |
|
| 87 |
+
# # Return the predictions
|
| 88 |
+
# return json.dumps({"class": predicted_class_label})
|
| 89 |
|
| 90 |
+
# except requests.exceptions.RequestException as e:
|
| 91 |
+
# return json.dumps({"error": f"Request error: {str(e)}"})
|
| 92 |
+
# except Exception as e:
|
| 93 |
+
# return json.dumps({"error": f"An unexpected error occurred: {str(e)}"})
|
| 94 |
+
|
| 95 |
+
@app.route('/answer',methods=['POST'])
|
| 96 |
+
def answer():
|
| 97 |
+
api_key=os.getenv("GOOGLE_API_KEY")
|
| 98 |
+
genai.configure(api_key=api_key)
|
| 99 |
+
model=genai.GenerativeModel('gemini-pro')
|
| 100 |
+
query=request.get_json()['query']
|
| 101 |
+
final_query=f"""
|
| 102 |
+
Following are negative reviews about my products, suggest what are the key issues from the customer feedback:{query}
|
| 103 |
+
"""
|
| 104 |
+
response = model.generate_content(final_query)
|
| 105 |
+
return json.dumps({"message":response.text})
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
| 108 |
app.run(debug=True)
|
requirements.txt
CHANGED
|
@@ -1,22 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
blinker==1.7.0
|
| 2 |
-
|
| 3 |
-
certifi==
|
| 4 |
charset-normalizer==3.3.2
|
| 5 |
click==8.1.7
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
filelock==3.13.1
|
| 7 |
-
|
|
|
|
| 8 |
Flask-Cors==4.0.0
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
idna==3.6
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
itsdangerous==2.1.2
|
| 14 |
-
Jinja2==3.1.
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
mpmath==1.3.0
|
|
|
|
|
|
|
| 18 |
networkx==3.2.1
|
| 19 |
-
numpy==1.26.
|
| 20 |
nvidia-cublas-cu12==12.1.3.1
|
| 21 |
nvidia-cuda-cupti-cu12==12.1.105
|
| 22 |
nvidia-cuda-nvrtc-cu12==12.1.105
|
|
@@ -26,33 +78,74 @@ nvidia-cufft-cu12==11.0.2.54
|
|
| 26 |
nvidia-curand-cu12==10.3.2.106
|
| 27 |
nvidia-cusolver-cu12==11.4.5.107
|
| 28 |
nvidia-cusparse-cu12==12.1.0.106
|
| 29 |
-
nvidia-nccl-cu12==2.
|
| 30 |
-
nvidia-nvjitlink-cu12==12.
|
| 31 |
nvidia-nvtx-cu12==12.1.105
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
packaging==23.2
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
PyYAML==6.0.1
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
requests==2.31.0
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
sympy==1.12
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
Werkzeug==3.0.1
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
torch
|
| 58 |
-
bs4
|
|
|
|
| 1 |
+
affine==2.4.0
|
| 2 |
+
aiohttp==3.9.3
|
| 3 |
+
aiosignal==1.3.1
|
| 4 |
+
alabaster==0.7.16
|
| 5 |
+
albumentations==1.4.1
|
| 6 |
+
annotated-types==0.6.0
|
| 7 |
+
anyio==4.3.0
|
| 8 |
+
attrs==23.2.0
|
| 9 |
+
Babel==2.14.0
|
| 10 |
+
beautifulsoup4==4.12.3
|
| 11 |
blinker==1.7.0
|
| 12 |
+
cachetools==5.3.3
|
| 13 |
+
certifi==2024.2.2
|
| 14 |
charset-normalizer==3.3.2
|
| 15 |
click==8.1.7
|
| 16 |
+
click-plugins==1.1.1
|
| 17 |
+
cligj==0.7.2
|
| 18 |
+
commonmark==0.9.1
|
| 19 |
+
contourpy==1.2.0
|
| 20 |
+
cycler==0.12.1
|
| 21 |
+
dataclasses-json==0.6.4
|
| 22 |
+
deepforest @ file:///home/hawkeye/Desktop/DeepForest
|
| 23 |
+
distlib==0.3.8
|
| 24 |
+
docutils==0.20.1
|
| 25 |
filelock==3.13.1
|
| 26 |
+
fiona==1.9.5
|
| 27 |
+
Flask==3.0.2
|
| 28 |
Flask-Cors==4.0.0
|
| 29 |
+
fonttools==4.49.0
|
| 30 |
+
frozenlist==1.4.1
|
| 31 |
+
fsspec==2024.2.0
|
| 32 |
+
geopandas==0.14.3
|
| 33 |
+
google==3.0.0
|
| 34 |
+
google-ai-generativelanguage==0.4.0
|
| 35 |
+
google-api-core==2.18.0
|
| 36 |
+
google-auth==2.25.1
|
| 37 |
+
google-generativeai==0.4.1
|
| 38 |
+
googleapis-common-protos==1.63.0
|
| 39 |
+
greenlet==3.0.3
|
| 40 |
+
grpcio==1.62.1
|
| 41 |
+
grpcio-status==1.62.1
|
| 42 |
idna==3.6
|
| 43 |
+
imagecodecs==2024.1.1
|
| 44 |
+
imageio==2.34.0
|
| 45 |
+
imagesize==1.4.1
|
| 46 |
+
insta-scrape==2.1.2
|
| 47 |
+
instagramy==4.5
|
| 48 |
+
instaloader==4.11
|
| 49 |
itsdangerous==2.1.2
|
| 50 |
+
Jinja2==3.1.3
|
| 51 |
+
joblib==1.3.2
|
| 52 |
+
jsonpatch==1.33
|
| 53 |
+
jsonpointer==2.4
|
| 54 |
+
kiwisolver==1.4.5
|
| 55 |
+
langchain==0.1.13
|
| 56 |
+
langchain-community==0.0.29
|
| 57 |
+
langchain-core==0.1.33
|
| 58 |
+
langchain-google-genai==0.0.11
|
| 59 |
+
langchain-text-splitters==0.0.1
|
| 60 |
+
langsmith==0.1.31
|
| 61 |
+
lazy_loader==0.3
|
| 62 |
+
lightning-utilities==0.10.1
|
| 63 |
+
MarkupSafe==2.1.5
|
| 64 |
+
marshmallow==3.21.1
|
| 65 |
+
matplotlib==3.8.3
|
| 66 |
+
mock==5.1.0
|
| 67 |
mpmath==1.3.0
|
| 68 |
+
multidict==6.0.5
|
| 69 |
+
mypy-extensions==1.0.0
|
| 70 |
networkx==3.2.1
|
| 71 |
+
numpy==1.26.4
|
| 72 |
nvidia-cublas-cu12==12.1.3.1
|
| 73 |
nvidia-cuda-cupti-cu12==12.1.105
|
| 74 |
nvidia-cuda-nvrtc-cu12==12.1.105
|
|
|
|
| 78 |
nvidia-curand-cu12==10.3.2.106
|
| 79 |
nvidia-cusolver-cu12==11.4.5.107
|
| 80 |
nvidia-cusparse-cu12==12.1.0.106
|
| 81 |
+
nvidia-nccl-cu12==2.19.3
|
| 82 |
+
nvidia-nvjitlink-cu12==12.4.99
|
| 83 |
nvidia-nvtx-cu12==12.1.105
|
| 84 |
+
opencv-python==4.9.0.80
|
| 85 |
+
opencv-python-headless==4.9.0.80
|
| 86 |
+
orjson==3.9.15
|
| 87 |
packaging==23.2
|
| 88 |
+
pandas==2.2.1
|
| 89 |
+
pillow==10.2.0
|
| 90 |
+
platformdirs==4.2.0
|
| 91 |
+
progressbar2==4.4.2
|
| 92 |
+
proto-plus==1.23.0
|
| 93 |
+
protobuf==4.25.3
|
| 94 |
+
psutil==5.9.8
|
| 95 |
+
pyasn1==0.5.1
|
| 96 |
+
pyasn1-modules==0.3.0
|
| 97 |
+
pycocotools==2.0.7
|
| 98 |
+
pydantic==2.6.4
|
| 99 |
+
pydantic_core==2.16.3
|
| 100 |
+
Pygments==2.17.2
|
| 101 |
+
pyparsing==3.1.2
|
| 102 |
+
pyproj==3.6.1
|
| 103 |
+
python-dateutil==2.9.0.post0
|
| 104 |
+
python-dotenv==1.0.1
|
| 105 |
+
python-utils==3.8.2
|
| 106 |
+
pytorch-lightning==2.2.1
|
| 107 |
+
pytz==2024.1
|
| 108 |
PyYAML==6.0.1
|
| 109 |
+
rasterio==1.3.9
|
| 110 |
+
readthedocs-build==2.0.9
|
| 111 |
+
readthedocs-sphinx-ext==2.2.5
|
| 112 |
+
recommonmark==0.7.1
|
| 113 |
requests==2.31.0
|
| 114 |
+
rsa==4.9
|
| 115 |
+
Rtree==1.2.0
|
| 116 |
+
scikit-image==0.22.0
|
| 117 |
+
scikit-learn==1.4.1.post1
|
| 118 |
+
scipy==1.12.0
|
| 119 |
+
setuptools==68.2.2
|
| 120 |
+
shapely==2.0.3
|
| 121 |
+
six==1.16.0
|
| 122 |
+
slidingwindow==0.0.14
|
| 123 |
+
sniffio==1.3.1
|
| 124 |
+
snowballstemmer==2.2.0
|
| 125 |
+
snuggs==1.4.7
|
| 126 |
+
soupsieve==2.5
|
| 127 |
+
Sphinx==7.2.6
|
| 128 |
+
sphinxcontrib-applehelp==1.0.8
|
| 129 |
+
sphinxcontrib-devhelp==1.0.6
|
| 130 |
+
sphinxcontrib-htmlhelp==2.0.5
|
| 131 |
+
sphinxcontrib-jsmath==1.0.1
|
| 132 |
+
sphinxcontrib-qthelp==1.0.7
|
| 133 |
+
sphinxcontrib-serializinghtml==1.1.10
|
| 134 |
+
SQLAlchemy==2.0.28
|
| 135 |
sympy==1.12
|
| 136 |
+
tenacity==8.2.3
|
| 137 |
+
threadpoolctl==3.3.0
|
| 138 |
+
tifffile==2024.2.12
|
| 139 |
+
torch==2.2.1
|
| 140 |
+
torchmetrics==1.3.1
|
| 141 |
+
torchvision==0.17.1
|
| 142 |
+
tqdm==4.66.2
|
| 143 |
+
typing-inspect==0.9.0
|
| 144 |
+
typing_extensions==4.10.0
|
| 145 |
+
tzdata==2024.1
|
| 146 |
+
urllib3==2.2.1
|
| 147 |
+
virtualenv==20.25.1
|
| 148 |
Werkzeug==3.0.1
|
| 149 |
+
wheel==0.41.2
|
| 150 |
+
xmltodict==0.13.0
|
| 151 |
+
yarl==1.9.4
|
|
|
|
|
|