-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Project Tutorial Proposal - Dev-Docs(Andrew Van Beek) #29
Comments
Will be short tutorial on how to use hugging face and its API to train a very simple classifier. In my example I just detect whether it is the creator of Super Mario vs Minecraft. You need to create a .env file or replace API-KEY value or replace it in the python code manually. You can find your API Token here: https://huggingface.co/settings/tokens. Then just google image search Miyamoto or Perrson and have fun! index.html <html>
<head>
</head>
<body>
<h1>Is it Miyamoto or Perrson?!?</h1>
<form method="post" action="{{ url_for('upload') }}" enctype="multipart/form-data">
<input type="file" name="file1">
<input type="submit" value="Submit">
</form>
</body>
</html> web.py from flask import Flask, render_template, request, jsonify
import requests
import json
import os
from dotenv import load_dotenv
load_dotenv()
API_URL = "https://api-inference.huggingface.co/models/andrewvanbeek/autotrain-persson-versus-miyamoto-1990766287"
headers = {"Authorization": f'Bearer {os.getenv("HUGGING_FACE_API_KEY")}'}
app = Flask(__name__)
def query(data):
response = requests.request("POST", API_URL, headers=headers, data=data)
return json.loads(response.content.decode("utf-8"))
@app.route('/')
def index():
return render_template('./index.html')
@app.route('/upload', methods=['POST'])
def upload():
file = request.files['file1']
modeldata = query(file)
print(modeldata)
if modeldata[0]:
for person in modeldata:
if person['score'] > 0.60:
return f'It is probbaly {person["label"]}! The model result was {person["score"]}'
else:
return 'Likely it is neither of those folks'
else:
return jsonify(modeldata)
app.run(host='0.0.0.0', port=81) |
Hey @avb-is-me. Amazing code! Just a few changes:
Please let me know once you've made the changes! |
Sounds good @Bobliuuu. After I make those changes should I just start writing or do you want to review again? |
You can start writing once you make the changes! |
👍 |
The text was updated successfully, but these errors were encountered: