Skip to content

Commit 3c4b63f

Browse files
committed
Language Detection
1 parent f8a43c6 commit 3c4b63f

File tree

10 files changed

+11484
-8
lines changed

10 files changed

+11484
-8
lines changed

Language Detection/Language Detection.ipynb

Lines changed: 497 additions & 0 deletions
Large diffs are not rendered by default.

Language Detection/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# pblapi.github.io

Language Detection/app.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# importing libraries
2+
from flask import Flask, request, render_template
3+
import sklearn
4+
import pickle
5+
import pandas as pd
6+
import re
7+
import numpy as np
8+
from sklearn.feature_extraction.text import CountVectorizer
9+
from sklearn.naive_bayes import MultinomialNB
10+
from sklearn.preprocessing import LabelEncoder
11+
from googletrans import Translator
12+
le = LabelEncoder()
13+
14+
app = Flask(__name__)
15+
@app.route('/')
16+
17+
def home():
18+
return render_template("home.html")
19+
20+
@app.route("/predict", methods = ["POST"])
21+
22+
def predict():
23+
# loading the dataset
24+
data = pd.read_csv("language_detection.csv")
25+
y = data["Language"]
26+
27+
# label encoding
28+
y = le.fit_transform(y)
29+
30+
#loading the model and cv
31+
model = pickle.load(open("model.pkl", "rb"))
32+
cv = pickle.load(open("transform.pkl", "rb"))
33+
34+
if request.method == "POST":
35+
# taking the input
36+
text = request.form["text"]
37+
# preprocessing the text
38+
text = re.sub(r'[!@#$(),\n"%^*?\:;~`0-9]', '', text)
39+
text = re.sub(r'[[]]', '', text)
40+
text = text.lower()
41+
dat = [text]
42+
# creating the vector
43+
vect = cv.transform(dat).toarray()
44+
# prediction
45+
my_pred = model.predict(vect)
46+
my_pred = le.inverse_transform(my_pred)
47+
48+
return render_template("home.html", pred="{}".format(my_pred[0]))
49+
@app.route("/translate", methods=["POST"])
50+
def translate():
51+
translator = Translator()
52+
if request.method == "POST":
53+
# taking the input
54+
text = request.form["text"]
55+
# taking the target language
56+
target_lang = request.form["lang"]
57+
# translating the text
58+
translation = translator.translate(text, dest=target_lang)
59+
return render_template("home.html", translation=translation.text)
60+
61+
if __name__ =="__main__":
62+
app.run(debug=True)

Language Detection/language_detection.csv

Lines changed: 10781 additions & 0 deletions
Large diffs are not rendered by default.

Language Detection/model.pkl

10.2 MB
Binary file not shown.

Language Detection/requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Flask==1.1.2
2+
scikit-learn==0.23.1
3+
numpy==1.18.5
4+
pandas==1.1.4
5+
regex==2020.11.13
6+
Werkzeug==1.0.1
7+
gunicorn

Language Detection/static/style.css

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
font-size: 16px;
4+
}
5+
6+
h1 {
7+
text-align: center;
8+
}
9+
10+
form {
11+
margin: 20px auto;
12+
max-width: 500px;
13+
}
14+
15+
label {
16+
display: block;
17+
margin-bottom: 5px;
18+
}
19+
20+
textarea {
21+
display: block;
22+
width: 100%;
23+
padding: 10px;
24+
margin-bottom: 10px;
25+
border: 1px solid #ccc;
26+
border-radius: 3px;
27+
box-sizing: border-box;
28+
resize: vertical;
29+
}
30+
31+
select {
32+
display: block;
33+
padding: 5px;
34+
margin-bottom: 10px;
35+
border: 1px solid #ccc;
36+
border-radius: 3px;
37+
box-sizing: border-box;
38+
}
39+
40+
button[type="submit"] {
41+
display: block;
42+
padding: 10px 20px;
43+
background-color: #4CAF50;
44+
color: white;
45+
border: none;
46+
border-radius: 3px;
47+
cursor: pointer;
48+
}
49+
50+
button[type="submit"]:hover {
51+
background-color: #3e8e41;
52+
}
53+
54+
#result, #translation_result {
55+
margin: 20px auto;
56+
max-width: 500px;
57+
padding: 10px;
58+
border: 1px solid #ccc;
59+
border-radius: 3px;
60+
background-color: #f2f2f2;
61+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Language Detection</title>
6+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
7+
</head>
8+
<body>
9+
<h1>Language Detection</h1>
10+
<form id="language-detection" action="/predict" method="post">
11+
<label for="text">Enter text:</label>
12+
<textarea name="text" id="text" rows="5" cols="30"></textarea>
13+
<br>
14+
<button type="submit" name="action" value="detect">Detect language</button>
15+
</form>
16+
{% if pred %}
17+
<div id="result">
18+
<p>The entered text is in {{ pred }}</p>
19+
</div>
20+
{% endif %}
21+
</body>
22+
</html>

Language Detection/transform.pkl

1.74 MB
Binary file not shown.

Readme.md

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,62 @@
1-
# LINK SCRAPPER
1+
![Amazing-Python-Scripts](https://socialify.git.ci/avinashkranjan/Amazing-Python-Scripts/image?description=1&forks=1&issues=1&language=1&logo=https%3A%2F%2Fuser-images.githubusercontent.com%2F55796944%2F104455539-7258a200-55cd-11eb-90dc-7c9981e73d72.png&owner=1&pulls=1&stargazers=1&theme=Light)
22

3+
[![forthebadge](https://forthebadge.com/images/badges/built-by-developers.svg)](https://forthebadge.com)
4+
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
5+
[![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](https://forthebadge.com)
6+
[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)
37

4-
- It is used to scrape links from any website and display it.
8+
[![GitHub issues](https://img.shields.io/github/issues/avinashkranjan/Amazing-Python-Scripts.svg)](https://github.com/avinashkranjan/Amazing-Python-Scripts/issues)
9+
[![GitHub issues closed](https://img.shields.io/github/issues-closed/avinashkranjan/Amazing-Python-Scripts.svg)](https://github.com/avinashkranjan/Amazing-Python-Scripts/issues?q=is%3Aissue+is%3Aclosed)
10+
[![GitHub pull requests](https://img.shields.io/github/issues-pr/avinashkranjan/Amazing-Python-Scripts.svg)](https://github.com/avinashkranjan/Amazing-Python-Scripts/pulls)
11+
[![GitHub pull requests](https://img.shields.io/github/issues-pr-closed/avinashkranjan/Amazing-Python-Scripts.svg)](https://github.com/avinashkranjan/Amazing-Python-Scripts/pulls?q=is%3Apr+is%3Aclosed) ![GitHub repo size](https://img.shields.io/github/repo-size/avinashkranjan/Amazing-Python-Scripts?color=yellow)
12+
![Lines of Code](https://img.shields.io/tokei/lines/github/avinashkranjan/Amazing-Python-Scripts?color=red&label=Lines%20of%20Code)
513

14+
<h2 align=center> 📑 Introduction </h2>
615

7-
## Setup instructions
16+
A curated collection of **Amazing Python scripts** from **_Basics to Advance with automation task scripts_**. This is your Personal space to find or add any new script
17+
that can make Life Easier for you, as a **_Developer_**, and find a utility of coding to burst out of boredom. Get started with coding exhilarating scripts that you can use to **_download PDFs from an Online Source or just to randomly like everyone's Instagram Post_**.
818

9-
Any PC with python 3 installed can run this code.
19+
<h2 align=center> 📃 Scripts Available </h2>
20+
<p align="center">
21+
<a href="https://github.com/avinashkranjan/Amazing-Python-Scripts/blob/master/SCRIPTS.md">
22+
<img src="https://forthebadge.com/images/badges/check-it-out.svg">
23+
</a>
1024

25+
<h2 align=center> 👨🏻‍💻 How to get started? </h2>
1126

12-
## Output
13-
image.png
27+
You can refer to the following articles on **_basics of Git and Github and also contact the Project Mentors, in case you are stuck_**:
1428

15-
## Author(s)
29+
- [Forking a Repo](https://help.github.com/en/github/getting-started-with-github/fork-a-repo)
30+
- [Cloning a Repo](https://help.github.com/en/desktop/contributing-to-projects/creating-a-pull-request)
31+
- [How to create a Pull Request](https://opensource.com/article/19/7/create-pull-request-github)
32+
- [Getting started with Git and GitHub](https://towardsdatascience.com/getting-started-with-git-and-github-6fcd0f2d4ac6)
1633

17-
Tanya Mohanka
34+
35+
<h2 align=center> 📝 How to Contribute? </h2>
36+
37+
- Take a look at [Contributing Guide](https://github.com/avinashkranjan/Amazing-Python-Scripts/blob/master/CONTRIBUTING.md)
38+
- Take a look at the Existing Issues or create your own Issues!
39+
- Wait for the Issue to be assigned to you after which you can start working on it.
40+
- Fork the Repo and create a Branch for any Issue that you are working upon.
41+
- Create a Pull Request which will be promptly reviewed and suggestions would be added to improve it.
42+
- Add Screenshots to help us know what this Script is all about.
43+
44+
<h2 align=center> ✨ Contributors </h2>
45+
46+
Thanks go to these **Wonderful People** 👨🏻‍💻: 🚀 **Contributions** of any kind are welcome!
47+
48+
<table>
49+
<tr>
50+
<td>
51+
<a href="https://github.com/avinashkranjan/Amazing-Python-Scripts/graphs/contributors">
52+
<img src="https://contrib.rocks/image?repo=avinashkranjan/Amazing-Python-Scripts" />
53+
</a>
54+
</td>
55+
</tr>
56+
</table>
57+
58+
<h2 align=center> 🌟 Stargazers Over Time 🌟 </h2>
59+
60+
[![Stargazers over time](https://starchart.cc/avinashkranjan/Amazing-Python-Scripts.svg)](https://starchart.cc/avinashkranjan/Amazing-Python-Scripts)
61+
62+
<h1 align=center>Happy Coding 👨‍💻 </h1>

0 commit comments

Comments
 (0)