Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,61 +7,68 @@ import nltk
|
|
| 7 |
import gradio as gr
|
| 8 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import gradio as gr
|
| 8 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 9 |
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
current_path = os.getcwd()
|
| 13 |
+
|
| 14 |
+
print(f"The current working directory is: {current_path}")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# class HadithClassificationApp:
|
| 18 |
+
# def __init__(self):
|
| 19 |
+
# # Download NLTK resources if needed
|
| 20 |
+
# nltk.download('punkt')
|
| 21 |
+
|
| 22 |
+
# # Load the dataset and labels
|
| 23 |
+
# self.dataset = pd.read_csv("Preprocess_LK_Hadith_dataset.csv")
|
| 24 |
+
# self.labels = self.dataset['Arabic_Grade']
|
| 25 |
+
|
| 26 |
+
# # Load the models
|
| 27 |
+
# with open("tfidf_vectorizer.pkl", "rb") as f:
|
| 28 |
+
# self.vectorizer = pickle.load(f)
|
| 29 |
+
# with open("cosine_similarity_model.pkl", "rb") as f:
|
| 30 |
+
# self.X = pickle.load(f)
|
| 31 |
+
|
| 32 |
+
# @staticmethod
|
| 33 |
+
# def remove_tashkeel(text):
|
| 34 |
+
# tashkeel_pattern = re.compile(r'[\u0617-\u061A\u064B-\u0652]')
|
| 35 |
+
# return re.sub(tashkeel_pattern, '', text)
|
| 36 |
+
|
| 37 |
+
# def preprocess_arabic_text(self, text):
|
| 38 |
+
# text = self.remove_tashkeel(text)
|
| 39 |
+
# tokens = nltk.word_tokenize(text)
|
| 40 |
+
# cleaned_tokens = [token for token in tokens if token.isalnum()]
|
| 41 |
+
# lowercase_tokens = [token.lower() for token in cleaned_tokens]
|
| 42 |
+
# return " ".join(lowercase_tokens)
|
| 43 |
+
|
| 44 |
+
# def predict_label(self, input_text, threshold=0.5):
|
| 45 |
+
# input_text = self.preprocess_arabic_text(input_text)
|
| 46 |
+
# input_vector = self.vectorizer.transform([input_text])
|
| 47 |
+
# similarities = cosine_similarity(input_vector, self.X).flatten()
|
| 48 |
+
|
| 49 |
+
# max_index = np.argmax(similarities)
|
| 50 |
+
# max_similarity = similarities[max_index]
|
| 51 |
+
|
| 52 |
+
# if max_similarity >= threshold:
|
| 53 |
+
# return self.labels.iloc[max_index]
|
| 54 |
+
# else:
|
| 55 |
+
# return "No similar text found in dataset"
|
| 56 |
+
|
| 57 |
+
# def classify_hadith(self, input_text):
|
| 58 |
+
# return self.predict_label(input_text)
|
| 59 |
+
|
| 60 |
+
# if __name__ == "__main__":
|
| 61 |
+
# # Initialize the app
|
| 62 |
+
# hadith_classification_app = HadithClassificationApp()
|
| 63 |
+
|
| 64 |
+
# # Set up the Gradio interface
|
| 65 |
+
# iface = gr.Interface(
|
| 66 |
+
# fn=hadith_classification_app.classify_hadith,
|
| 67 |
+
# inputs="text",
|
| 68 |
+
# outputs="text",
|
| 69 |
+
# title="Hadith Classification App",
|
| 70 |
+
# description="Classify Hadith text based on pre-trained model."
|
| 71 |
+
# )
|
| 72 |
+
|
| 73 |
+
# # Launch the Gradio interface
|
| 74 |
+
# iface.launch()
|