Spaces:
Running
Running
deveix
commited on
Commit
·
c883d77
1
Parent(s):
8b248fd
add quran
Browse files- app/main.py +25 -18
- app/quran.csv +0 -0
- requirements.txt +2 -1
app/main.py
CHANGED
@@ -8,7 +8,7 @@ import uvicorn
|
|
8 |
from dotenv import load_dotenv
|
9 |
from fastapi.middleware.cors import CORSMiddleware
|
10 |
from uuid import uuid4
|
11 |
-
import httpx
|
12 |
|
13 |
import joblib
|
14 |
import librosa
|
@@ -113,18 +113,21 @@ def index_file(filepath):
|
|
113 |
|
114 |
return index
|
115 |
|
116 |
-
async def get_ayah_info(ayah):
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
128 |
""" Retrieve specific blocks from a file based on block numbers, where each block is separated by '\n\n'. """
|
129 |
blocks_text = []
|
130 |
with open(filepath, 'r', encoding='utf-8') as file:
|
@@ -133,20 +136,24 @@ async def get_text_by_block_number(filepath, block_numbers):
|
|
133 |
|
134 |
for block_number, block in enumerate(blocks, 1): # Starting block numbers at 1 for human readability
|
135 |
if block_number in block_numbers:
|
136 |
-
print(block)
|
137 |
splitted = block.split('\n')
|
138 |
ayah = splitted[0]
|
139 |
tafsir = splitted[1]
|
140 |
# Replace single newlines within blocks with space and strip leading/trailing whitespace
|
141 |
-
ayah_info = await get_ayah_info(ayah) # This makes the API call
|
|
|
|
|
|
|
142 |
blocks_text.append({
|
143 |
-
"ayah": ayah.replace(" ", ''),
|
|
|
|
|
144 |
"tafsir": tafsir,
|
145 |
-
|
146 |
-
# "block": formatted_block
|
147 |
})
|
148 |
if len(blocks_text) == len(block_numbers): # Stop reading once all required blocks are retrieved
|
149 |
break
|
|
|
150 |
return blocks_text
|
151 |
|
152 |
|
|
|
8 |
from dotenv import load_dotenv
|
9 |
from fastapi.middleware.cors import CORSMiddleware
|
10 |
from uuid import uuid4
|
11 |
+
# import httpx
|
12 |
|
13 |
import joblib
|
14 |
import librosa
|
|
|
113 |
|
114 |
return index
|
115 |
|
116 |
+
# async def get_ayah_info(ayah):
|
117 |
+
# """Asynchronously fetches Ayah information from the Al-Quran API."""
|
118 |
+
# url = f"https://api.alquran.cloud/v1/search/{ayah}/all/ar"
|
119 |
+
# async with httpx.AsyncClient() as client:
|
120 |
+
# response = await client.get(url)
|
121 |
+
# if response.status_code == 200:
|
122 |
+
# return response.json()
|
123 |
+
# else:
|
124 |
+
# return {"error": "Failed to fetch data"}
|
125 |
+
|
126 |
+
# async
|
127 |
+
import pandas as pd
|
128 |
+
df = pd.read_csv('/app/quran.csv')
|
129 |
+
|
130 |
+
def get_text_by_block_number(filepath, block_numbers):
|
131 |
""" Retrieve specific blocks from a file based on block numbers, where each block is separated by '\n\n'. """
|
132 |
blocks_text = []
|
133 |
with open(filepath, 'r', encoding='utf-8') as file:
|
|
|
136 |
|
137 |
for block_number, block in enumerate(blocks, 1): # Starting block numbers at 1 for human readability
|
138 |
if block_number in block_numbers:
|
|
|
139 |
splitted = block.split('\n')
|
140 |
ayah = splitted[0]
|
141 |
tafsir = splitted[1]
|
142 |
# Replace single newlines within blocks with space and strip leading/trailing whitespace
|
143 |
+
# ayah_info = await get_ayah_info(ayah) # This makes the API call
|
144 |
+
row_data = df.iloc[block_number].to_dict()
|
145 |
+
print(row_data)
|
146 |
+
|
147 |
blocks_text.append({
|
148 |
+
# "ayah": ayah.replace(" ", ''),
|
149 |
+
# "tafsir": tafsir,
|
150 |
+
# "ayah": ayah.replace(" ", ''),
|
151 |
"tafsir": tafsir,
|
152 |
+
**row_data
|
|
|
153 |
})
|
154 |
if len(blocks_text) == len(block_numbers): # Stop reading once all required blocks are retrieved
|
155 |
break
|
156 |
+
|
157 |
return blocks_text
|
158 |
|
159 |
|
app/quran.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
CHANGED
@@ -20,4 +20,5 @@ python-multipart
|
|
20 |
ffmpeg-python
|
21 |
noisereduce
|
22 |
scikit-learn==1.2.2
|
23 |
-
httpx
|
|
|
|
20 |
ffmpeg-python
|
21 |
noisereduce
|
22 |
scikit-learn==1.2.2
|
23 |
+
# httpx
|
24 |
+
pandas
|