Skip to content

Commit 18c8fa7

Browse files
committed
Flask api for image to template conversion added. Readme Updated.
1 parent 0420153 commit 18c8fa7

File tree

8 files changed

+148
-15
lines changed

8 files changed

+148
-15
lines changed

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Well we all have been working in Open Source and committing various Pull request
1414
- Real time tracking of commits, PR's and other contributions.
1515
- Contributors list based on number of PR's, merged pulls and other activities.
1616
- Contribution history of each contributor.
17+
can create a badge for your organization.]
18+
- upload and use the templates
1719

1820
The other part of this project includes the “notifying moderator” since we see sometimes that there are many PRs being sent, or issues being opened by various people across the globe but there are limited numbers of maintainers merging the PRs. This way organisations usually lose their potential contributors due to following things:
1921

@@ -26,9 +28,25 @@ The other part of this project includes the “notifying moderator” since we s
2628

2729
For instance, suppose a contributor “X” has been quite active within the community by working on various PRs, opening and resolving various issues, active on chat channels but after a month “X” gets disappeared. So by using this dashboard they will have a badge interface. There will be a badge attached in front of the name of the contributor. Let the name of the badge be “Y” so this badge will have a unique color. So as the time passes like “ a day went, 1 week went, 2 weeks went, a month, etc) this badges will get keep on fading. And Every fade color will have a unique reason. For example, when a contributor made a PR, the badge appeared “Red” in color. This badge will remain in the same color as long as he/she is contributing. Assume that contributor stops contributing and has not contributed for a week so his badge will become green in color. And this will keep on notifying mainaters, Admins about their disappearing. This way the organisations will have greater eye on the contributors and can help them sustain with the community.
2830

31+
## Install and Run
32+
33+
**Step 1:-** clone the repository
34+
35+
``` git clone https://github.com/username/Codebadge.git ```
36+
**Step 2:-** install frontend dependencies and run frontend server
37+
``` npm install && npm run serve```
38+
**Step 3:-** install flask api dependencies and run api
39+
```
40+
cd backend
41+
virtualenv -p python3 venv
42+
source venv/bin/activate
43+
pip install -r requirements.txt
44+
FLASK_APP=run.py flask run
45+
```
46+
2947
## Stack used
3048

31-
This will have a dashboard, where these things can be placed. The stack used can be any but since the organisation have fixed stack so its better to stick to Nodejs, Vue, React.
49+
This will have a dashboard, where these things can be placed. The stack used can be any but since the organisation have fixed stack so its better to stick to Nodejs, Vue, React. Flask is used as an machine learning api.
3250

3351
## Benefits to the community
3452

backend/requirements.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Flask==1.1.1
2+
Flask-Cors==3.0.8
3+
numpy==1.16.5
4+
opencv-python==4.1.1.26
5+
requests==2.22.0
6+
Werkzeug==0.16.0

backend/run.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from flask import Flask, render_template, jsonify,send_file,request
2+
from random import *
3+
from flask_cors import CORS
4+
import requests
5+
import numpy as np
6+
from cv2 import cv2
7+
from werkzeug.utils import secure_filename
8+
import os
9+
app = Flask(__name__,
10+
static_folder = "./dist/static",
11+
template_folder = "./dist")
12+
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
13+
14+
@app.route('/api/random')
15+
def random_number():
16+
response = {
17+
'randomNumber': randint(1, 100)
18+
}
19+
return jsonify(response)
20+
21+
@app.route('/api/upload',methods=["POST"])
22+
def upload():
23+
# file=request.files['temp']
24+
f=request.files['temp']
25+
tempname=request.form['tempname']
26+
temp_path='../templates/'
27+
name = f.filename.replace(' ','_')
28+
print(tempname)
29+
f.save(secure_filename(f.filename))
30+
31+
inputImage = cv2.imread(name)
32+
inputImageGray = cv2.cvtColor(inputImage, cv2.COLOR_BGR2GRAY)
33+
34+
edges = cv2.Canny(inputImageGray,150,200,apertureSize = 3)
35+
36+
print(edges)
37+
edges = abs(cv2.subtract(255,edges))
38+
39+
minLineLength = 30
40+
maxLineGap = 5
41+
lines = cv2.HoughLinesP(edges,cv2.HOUGH_PROBABILISTIC, np.pi/180, 30, minLineLength,maxLineGap)
42+
for x in range(0, len(lines)):
43+
for x1,y1,x2,y2 in lines[x]:
44+
pts = np.array([[x1, y1 ], [x2 , y2]], np.int32)
45+
cv2.polylines(inputImage, [pts], True, (0,255,0))
46+
47+
font = cv2.FONT_HERSHEY_SIMPLEX
48+
cv2.putText(inputImage,"Tracks Detected", (500, 250), font, 0.5, 255)
49+
50+
cv2.imwrite(temp_path+tempname+'.jpeg',edges)
51+
cv2.waitKey(0)
52+
53+
os.remove(name)
54+
55+
filename=tempname+'.jpeg'
56+
return send_file(temp_path+filename,mimetype='image/jpeg')

backend/run.pyc

2.47 KB
Binary file not shown.

src/App.vue

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<v-app>
33
<v-toolbar color="white" app>
44
<v-toolbar-title class="headline text-uppercase">
5+
<a href='http://localhost:8080/upload'>upload file</a>
56
<span>Codebadge</span>
67
<span class="font-weight-light text-none">&nbsp;(Production Stage)</span>
78
</v-toolbar-title>
@@ -29,4 +30,7 @@ export default {
2930
.content {
3031
background-color: white;
3132
}
33+
a{
34+
float:right;
35+
}
3236
</style>

src/router.js

+28-14
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,50 @@
1-
import Vue from 'vue';
2-
import Router from 'vue-router';
3-
import AuthView from './views/AuthView';
4-
import HomeView from './views/HomeView';
5-
import OrgView from './views/OrgView';
6-
import AuthService from './services/authService';
1+
import Vue from "vue";
2+
import Router from "vue-router";
3+
import AuthView from "./views/AuthView";
4+
import HomeView from "./views/HomeView.vue";
5+
import OrgView from "./views/OrgView";
6+
import AuthService from "./services/authService";
7+
import CreateBadge from "./views/CreateBadge";
8+
import Upload from "./views/Upload/Upload.vue";
79

810
Vue.use(Router);
911

1012
const authService = new AuthService();
1113

1214
export default new Router({
15+
mode: "history",
16+
base: process.env.BASE_URL,
1317
routes: [
1418
{
15-
path: '',
16-
redirect: 'auth'
19+
path: "",
20+
redirect: "auth"
1721
},
1822
{
19-
path: '/auth',
20-
name: 'authView',
23+
path: "/upload",
24+
name: "Upload",
25+
component: Upload
26+
},
27+
{
28+
path: "/auth",
29+
name: "authView",
2130
component: AuthView
2231
},
2332
{
24-
path: '/home',
25-
name: 'homeView',
33+
path: "/create",
34+
name: "CreateBadge",
35+
component: CreateBadge
36+
},
37+
{
38+
path: "/home",
39+
name: "homeView",
2640
component: HomeView,
2741
beforeEnter: (to, from, next) => {
2842
next(authService.isLoggedIn());
2943
}
3044
},
3145
{
32-
path: '/org/:name',
33-
name: 'orgView',
46+
path: "/org/:name",
47+
name: "orgView",
3448
component: OrgView,
3549
beforeEnter: (to, from, next) => {
3650
next(authService.isLoggedIn());

src/views/CreateBadge.vue

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<div>
3+
<b-card title="Card Title" no-body>
4+
<b-card-header header-tag="nav">
5+
<b-nav card-header tabs>
6+
<b-nav-item active>Active</b-nav-item>
7+
<b-nav-item>Inactive</b-nav-item>
8+
<b-nav-item disabled>Disabled</b-nav-item>
9+
</b-nav>
10+
</b-card-header>
11+
12+
<b-card-body class="text-center">
13+
<b-card-text>
14+
With supporting text below as a natural lead-in to additional content.
15+
</b-card-text>
16+
17+
<b-button variant="primary">Go somewhere</b-button>
18+
</b-card-body>
19+
</b-card>
20+
</div>
21+
</template>
22+
<script>
23+
export default {
24+
name: "CreateBadge"
25+
};
26+
</script>

src/views/Upload/Upload.vue

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<div>
3+
<form action="http://localhost:5000/api/upload" method="POST" enctype="multipart/form-data">
4+
<input type="file" name="temp" id="temp">
5+
<input name="tempname" placeholder="Give your template name">
6+
<button type="submit">Upload</button>
7+
</form>
8+
</div>
9+
</template>

0 commit comments

Comments
 (0)