Spaces:
Runtime error
Runtime error
vishaldhakal96
commited on
Commit
•
ad9dd7b
1
Parent(s):
5155698
Add application file
Browse files- Dockerfile +12 -0
- __pycache__/app.cpython-39.pyc +0 -0
- app.py +113 -0
- compose-dev.yaml +12 -0
- docker-compose.yml +12 -0
- requirements.txt +4 -0
Dockerfile
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9.18
|
2 |
+
|
3 |
+
COPY requirements.txt .
|
4 |
+
|
5 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
6 |
+
|
7 |
+
COPY . .
|
8 |
+
|
9 |
+
EXPOSE 7860
|
10 |
+
|
11 |
+
CMD ["flask", "run", "--host=0.0.0.0", "--port=7860"]
|
12 |
+
|
__pycache__/app.cpython-39.pyc
ADDED
Binary file (5.72 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from transformers import AutoModel, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
# Load the Nepali sentence similarity model
|
8 |
+
model_name = "l3cube-pune/indic-sentence-similarity-sbert"
|
9 |
+
model = AutoModel.from_pretrained(model_name)
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
torch.save(model,"model.pt")
|
12 |
+
|
13 |
+
model_2 = torch.load("model.pt")
|
14 |
+
# Load your array of sentences
|
15 |
+
sentence_array = [
|
16 |
+
"घर/जग्गा नामसारीको सिफारिस गरी पाऊँ",
|
17 |
+
"मोही लगत कट्टाको सिफारिस पाउं",
|
18 |
+
"घर कायम सिफारीस पाउं",
|
19 |
+
"अशक्त सिफारिस",
|
20 |
+
"छात्रबृत्तिको लागि सिफारिस पाऊँ",
|
21 |
+
"आदिवासी जनजाति प्रमाणित गरी पाऊँ",
|
22 |
+
"अस्थायी बसोबासको सिफारिस पाऊँ",
|
23 |
+
"स्थायी बसोबासको सिफारिस गरी पाऊँ",
|
24 |
+
"आर्थिक अवस्था कमजोर सिफारिस पाऊँ",
|
25 |
+
"नयाँ घरमा विद्युत जडान सिफारिस पाऊँ",
|
26 |
+
"धारा जडान सिफारिस पाऊँ",
|
27 |
+
"दुबै नाम गरेको ब्यक्ति एक्कै हो भन्ने सिफारिस पाऊँ",
|
28 |
+
"ब्यवसाय बन्द सिफारिस पाऊँ",
|
29 |
+
"व्यवसाय ठाउँसारी सिफारिस पाऊँ",
|
30 |
+
"कोर्ट–फिमिनाहा सिफारिस पाऊँ",
|
31 |
+
"नाबालक सिफारिस पाऊँ",
|
32 |
+
"चौपाया सिफारिस पाऊँ",
|
33 |
+
"संस्था दर्ता गरी पाऊँ",
|
34 |
+
"विद्यालय ठाउँसारी सिफारिस पाऊँ",
|
35 |
+
"विद्यालय संचालन/कक्षा बृद्धिको सिफारिस पाऊँ",
|
36 |
+
"जग्गा दर्ता सिफारिस पाऊँ",
|
37 |
+
"संरक्षक सिफारिस पाऊँ",
|
38 |
+
"बाटो कायम सिफारिस पाऊँ",
|
39 |
+
"जिवित नाता प्रमाणित गरी पाऊँ",
|
40 |
+
"मृत्यु नाता प्रमाणित गरी पाऊँ",
|
41 |
+
"निःशुल्क स्वास्थ्य उपचारको लागि सिफारिस पाऊँ",
|
42 |
+
"संस्था दर्ता सिफारिस पाऊँ",
|
43 |
+
"घर बाटो प्रमाणित गरी पाऊँ",
|
44 |
+
"चारकिल्ला प्रमाणित गरि पाउ",
|
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 |
+
@app.route('/check_similarity', methods=['POST'])
|
72 |
+
def check_similarity():
|
73 |
+
try:
|
74 |
+
#get data from form data
|
75 |
+
voice_text = request.form['voice_text']
|
76 |
+
|
77 |
+
# Sample voice input (replace this with your actual voice-to-text conversion)
|
78 |
+
""" voice_text = "कस्तो सिफारिस गर्नुपर्छ अस्थायी बसोबासको?" """
|
79 |
+
|
80 |
+
# Tokenize the voice_text
|
81 |
+
voice_inputs = tokenizer(voice_text, return_tensors="pt")
|
82 |
+
|
83 |
+
# Get the model output (embedding)
|
84 |
+
model_output = model(**voice_inputs).pooler_output
|
85 |
+
|
86 |
+
# Calculate similarity scores
|
87 |
+
similarity_scores = []
|
88 |
+
for sentence in sentence_array:
|
89 |
+
sentence_inputs = tokenizer(sentence, return_tensors="pt")
|
90 |
+
sentence_output = model(**sentence_inputs).pooler_output
|
91 |
+
|
92 |
+
# You might want to use a different score if the model provides one
|
93 |
+
similarity_score = torch.nn.functional.cosine_similarity(model_output, sentence_output).item()
|
94 |
+
similarity_scores.append(similarity_score)
|
95 |
+
|
96 |
+
# Find the most similar sentence
|
97 |
+
max_similarity_index = similarity_scores.index(max(similarity_scores))
|
98 |
+
most_similar_sentence = sentence_array[max_similarity_index]
|
99 |
+
|
100 |
+
result = {
|
101 |
+
"voice_text": voice_text,
|
102 |
+
"most_similar_sentence": most_similar_sentence,
|
103 |
+
"max_similarity_index" : max_similarity_index,
|
104 |
+
"similarity_score": max(similarity_scores)
|
105 |
+
}
|
106 |
+
|
107 |
+
return jsonify(result)
|
108 |
+
|
109 |
+
except Exception as e:
|
110 |
+
return jsonify({"error": str(e)}), 500
|
111 |
+
|
112 |
+
if __name__ == '__main__':
|
113 |
+
app.run(port=5000, debug=True)
|
compose-dev.yaml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
services:
|
2 |
+
app:
|
3 |
+
entrypoint:
|
4 |
+
- sleep
|
5 |
+
- infinity
|
6 |
+
image: docker/dev-environments-default:stable-1
|
7 |
+
init: true
|
8 |
+
volumes:
|
9 |
+
- type: bind
|
10 |
+
source: /var/run/docker.sock
|
11 |
+
target: /var/run/docker.sock
|
12 |
+
|
docker-compose.yml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
version: '3.7'
|
2 |
+
|
3 |
+
|
4 |
+
services:
|
5 |
+
mlapp:
|
6 |
+
container_name: mlapp
|
7 |
+
image: manavkhadka0/mlapp
|
8 |
+
ports:
|
9 |
+
- "3000:3000"
|
10 |
+
build:
|
11 |
+
context: .
|
12 |
+
dockerfile: Dockerfile
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers==4.33.3
|
2 |
+
flask==2.2.2
|
3 |
+
torch==2.1.2
|
4 |
+
Werkzeug==2.2.2
|