umar-100 commited on
Commit
7a6d0f3
·
verified ·
1 Parent(s): 44150c0

Upload folder using huggingface_hub

Browse files
.github/workflows/update_space.yml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Run Python script
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Set up Python
17
+ uses: actions/setup-python@v2
18
+ with:
19
+ python-version: '3.9'
20
+
21
+ - name: Install Gradio
22
+ run: python -m pip install gradio
23
+
24
+ - name: Log in to Hugging Face
25
+ run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
26
+
27
+ - name: Deploy to Spaces
28
+ run: gradio deploy
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ venv
2
+ .env
.gradio/certificate.pem ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
3
+ TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
4
+ cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
5
+ WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
6
+ ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
7
+ MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0F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ByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
24
+ ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
25
+ TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
26
+ jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
27
+ oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
28
+ 4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
29
+ mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
30
+ emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
31
+ -----END CERTIFICATE-----
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mohd Umar Javaid
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,12 +1,14 @@
1
  ---
2
- title: Shayari
3
- emoji:
4
- colorFrom: yellow
5
- colorTo: gray
6
  sdk: gradio
7
  sdk_version: 5.15.0
8
- app_file: app.py
9
- pinned: false
10
  ---
 
 
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
1
  ---
2
+ title: shayari
3
+ app_file: app.py
 
 
4
  sdk: gradio
5
  sdk_version: 5.15.0
 
 
6
  ---
7
+ # Shayari Search App
8
+ ### Semantic search for poetry
9
 
10
+ # Tech stack used
11
+ - Langchain
12
+ - Mistral LLM
13
+ - Together Embeddings
14
+ - Pinecone Vector DB
__pycache__/utilis.cpython-311.pyc ADDED
Binary file (3.51 kB). View file
 
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_mistralai import ChatMistralAI
2
+ import os
3
+ from dotenv import load_dotenv
4
+ import gradio as gr
5
+ from utilis import retrieve, llm
6
+
7
+ load_dotenv()
8
+ MISTRAL_API_KEY=os.getenv("MISTRAL_API_KEY")
9
+ model=ChatMistralAI(
10
+ model="mistral-large-latest",
11
+ api_key=MISTRAL_API_KEY
12
+ )
13
+
14
+
15
+ with gr.Blocks(css=".gradio-container {background: url('image.png') !important;}") as Iface:
16
+ gr.Markdown("<h1>Search Shayari</h1>")
17
+ with gr.Row():
18
+ with gr.Column(scale=1):
19
+ query = gr.Textbox(label="Which type of shayari do you want to find?")
20
+ submit_button = gr.Button("Search")
21
+
22
+ with gr.Column(scale=2):
23
+ chatbot = gr.Chatbot(label="Matching results", height=600)
24
+ submit_button.click(
25
+ fn=llm,
26
+ inputs=[query, chatbot],
27
+ outputs=[chatbot, chatbot]
28
+
29
+ )
30
+ Iface.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ aiohappyeyeballs==2.4.6
3
+ aiohttp==3.10.11
4
+ aiosignal==1.3.2
5
+ annotated-types==0.7.0
6
+ anyio==4.8.0
7
+ argon2-cffi==23.1.0
8
+ argon2-cffi-bindings==21.2.0
9
+ arrow==1.3.0
10
+ asttokens==3.0.0
11
+ async-lru==2.0.4
12
+ attrs==25.1.0
13
+ babel==2.17.0
14
+ beautifulsoup4==4.13.3
15
+ bleach==6.2.0
16
+ certifi==2025.1.31
17
+ cffi==1.17.1
18
+ charset-normalizer==3.4.1
19
+ click==8.1.8
20
+ cohere==5.13.12
21
+ colorama==0.4.6
22
+ comm==0.2.2
23
+ dataclasses-json==0.6.7
24
+ debugpy==1.8.12
25
+ decorator==5.1.1
26
+ defusedxml==0.7.1
27
+ distro==1.9.0
28
+ executing==2.2.0
29
+ fastapi==0.115.8
30
+ fastavro==1.10.0
31
+ fastjsonschema==2.21.1
32
+ ffmpy==0.5.0
33
+ filelock==3.17.0
34
+ fqdn==1.5.1
35
+ frozenlist==1.5.0
36
+ fsspec==2025.2.0
37
+ gradio==5.15.0
38
+ gradio_client==1.7.0
39
+ greenlet==3.1.1
40
+ h11==0.14.0
41
+ httpcore==1.0.7
42
+ httpx==0.28.1
43
+ httpx-sse==0.4.0
44
+ huggingface-hub==0.28.1
45
+ idna==3.10
46
+ iniconfig==2.0.0
47
+ inquirerpy==0.3.4
48
+ ipykernel==6.29.5
49
+ ipython==8.32.0
50
+ ipywidgets==8.1.5
51
+ isoduration==20.11.0
52
+ jedi==0.19.2
53
+ Jinja2==3.1.5
54
+ jiter==0.8.2
55
+ json5==0.10.0
56
+ jsonpatch==1.33
57
+ jsonpointer==3.0.0
58
+ jsonschema==4.23.0
59
+ jsonschema-specifications==2024.10.1
60
+ jupyter-console==6.6.3
61
+ jupyter-events==0.12.0
62
+ jupyter-lsp==2.2.5
63
+ jupyter_client==8.6.3
64
+ jupyter_core==5.7.2
65
+ jupyter_server==2.15.0
66
+ jupyter_server_terminals==0.5.3
67
+ jupyterlab==4.3.5
68
+ jupyterlab_pygments==0.3.0
69
+ jupyterlab_server==2.27.3
70
+ jupyterlab_widgets==3.0.13
71
+ langchain==0.3.18
72
+ langchain-cohere==0.4.2
73
+ langchain-community==0.3.17
74
+ langchain-core==0.3.34
75
+ langchain-mistralai==0.2.6
76
+ langchain-openai==0.3.4
77
+ langchain-pinecone==0.2.2
78
+ langchain-tests==0.3.11
79
+ langchain-text-splitters==0.3.6
80
+ langchain-together==0.3.0
81
+ langgraph==0.2.70
82
+ langgraph-checkpoint==2.0.10
83
+ langgraph-sdk==0.1.51
84
+ langsmith==0.3.7
85
+ markdown-it-py==3.0.0
86
+ MarkupSafe==2.1.5
87
+ marshmallow==3.26.1
88
+ matplotlib-inline==0.1.7
89
+ mdurl==0.1.2
90
+ mistune==3.1.1
91
+ msgpack==1.1.0
92
+ multidict==6.1.0
93
+ mypy-extensions==1.0.0
94
+ nbclient==0.10.2
95
+ nbconvert==7.16.6
96
+ nbformat==5.10.4
97
+ nest-asyncio==1.6.0
98
+ notebook_shim==0.2.4
99
+ numpy==1.26.4
100
+ openai==1.61.1
101
+ orjson==3.10.15
102
+ overrides==7.7.0
103
+ packaging==24.2
104
+ pandas==2.2.3
105
+ pandocfilters==1.5.1
106
+ parso==0.8.4
107
+ pfzy==0.3.4
108
+ pillow==11.1.0
109
+ pinecone==5.4.2
110
+ pinecone-plugin-inference==3.1.0
111
+ pinecone-plugin-interface==0.0.7
112
+ platformdirs==4.3.6
113
+ pluggy==1.5.0
114
+ prometheus_client==0.21.1
115
+ prompt_toolkit==3.0.50
116
+ propcache==0.2.1
117
+ psutil==6.1.1
118
+ pure_eval==0.2.3
119
+ pycparser==2.22
120
+ pydantic==2.10.6
121
+ pydantic-settings==2.7.1
122
+ pydantic_core==2.27.2
123
+ pydub==0.25.1
124
+ Pygments==2.19.1
125
+ pytest==8.3.4
126
+ pytest-asyncio==0.25.3
127
+ pytest-socket==0.7.0
128
+ python-dateutil==2.9.0.post0
129
+ python-dotenv==1.0.1
130
+ python-json-logger==3.2.1
131
+ python-multipart==0.0.20
132
+ pytz==2025.1
133
+ pywin32==308
134
+ pywinpty==2.0.15
135
+ PyYAML==6.0.2
136
+ pyzmq==26.2.1
137
+ referencing==0.36.2
138
+ regex==2024.11.6
139
+ requests==2.32.3
140
+ requests-toolbelt==1.0.0
141
+ rfc3339-validator==0.1.4
142
+ rfc3986-validator==0.1.1
143
+ rich==13.9.4
144
+ rpds-py==0.22.3
145
+ ruff==0.9.5
146
+ safehttpx==0.1.6
147
+ semantic-version==2.10.0
148
+ Send2Trash==1.8.3
149
+ shellingham==1.5.4
150
+ six==1.17.0
151
+ sniffio==1.3.1
152
+ soupsieve==2.6
153
+ SQLAlchemy==2.0.38
154
+ stack-data==0.6.3
155
+ starlette==0.45.3
156
+ syrupy==4.8.1
157
+ tenacity==9.0.0
158
+ terminado==0.18.1
159
+ tiktoken==0.8.0
160
+ tinycss2==1.4.0
161
+ tokenizers==0.21.0
162
+ tomlkit==0.13.2
163
+ tornado==6.4.2
164
+ tqdm==4.67.1
165
+ traitlets==5.14.3
166
+ typer==0.15.1
167
+ types-python-dateutil==2.9.0.20241206
168
+ types-PyYAML==6.0.12.20241230
169
+ types-requests==2.32.0.20241016
170
+ typing-inspect==0.9.0
171
+ typing_extensions==4.12.2
172
+ tzdata==2025.1
173
+ uri-template==1.3.0
174
+ urllib3==2.3.0
175
+ uvicorn==0.34.0
176
+ wcwidth==0.2.13
177
+ webcolors==24.11.1
178
+ webencodings==0.5.1
179
+ websocket-client==1.8.0
180
+ websockets==14.2
181
+ widgetsnbextension==4.0.13
182
+ yarl==1.18.3
183
+ zstandard==0.23.0
utilis.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from langchain_pinecone import PineconeVectorStore
4
+ from pinecone import Pinecone
5
+ from langchain_together import TogetherEmbeddings
6
+ from langchain_mistralai import ChatMistralAI
7
+ import cohere
8
+ from langchain.retrievers.contextual_compression import ContextualCompressionRetriever
9
+ from langchain_cohere import CohereRerank
10
+
11
+
12
+ load_dotenv()
13
+ PINECONE_API_KEY=os.getenv("PINECONE_API_KEY")
14
+ MISTRAL_API_KEY=os.getenv("MISTRAL_API_KEY")
15
+ TOGETHER_API=os.getenv("TOGETHER_API")
16
+ COHERE_API_KEY=os.getenv("COHERE_API_KEY")
17
+
18
+ co = cohere.Client(COHERE_API_KEY)
19
+
20
+ embeddings = TogetherEmbeddings(
21
+ model="togethercomputer/m2-bert-80M-8k-retrieval",
22
+ api_key=TOGETHER_API
23
+ )
24
+
25
+ model=ChatMistralAI(
26
+ model="mistral-large-latest",
27
+ api_key=MISTRAL_API_KEY
28
+ )
29
+ pc = Pinecone(api_key=PINECONE_API_KEY)
30
+
31
+ index_name = "together"
32
+
33
+ index = pc.Index(index_name)
34
+
35
+ vector_store = PineconeVectorStore(index=index, embedding=embeddings)
36
+ retriever = vector_store.as_retriever()
37
+
38
+ compressor = CohereRerank(model="rerank-v3.5")
39
+ compression_retriever = ContextualCompressionRetriever(
40
+ base_compressor=compressor, base_retriever=retriever
41
+ )
42
+
43
+ def retrieve(query):
44
+ compressed_docs = compression_retriever.invoke(query)
45
+
46
+ return compressed_docs[0]
47
+
48
+ def llm(query, history):
49
+ query=model.invoke(f"You are a helpful AI assistant. Translate the following query to urdu if the query is in urdu then return the same query. Query: {query}. Remember just translate the query and nothing else.").content
50
+ results=retrieve(query)
51
+ prompt=f""""
52
+ You are a helpful AI Assistant and your job is to help user find relevant shayari.
53
+ The query is {query}
54
+ The matching result after semantic search is {results.page_content}. You may exclude interpretation given in the results. Just respond from the context.
55
+ """
56
+
57
+ try:
58
+ response=model.invoke(prompt).content
59
+ history = history or []
60
+ history.append(("You", query))
61
+ history.append(("Assistant", results.page_content))
62
+ return history, history
63
+ except Exception as e:
64
+ return history, history + [("Bot", f"Error in API request: {str(e)}")]
65
+