Erfan11 commited on
Commit
e178f41
1 Parent(s): 3b6ae92

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModel, AutoTokenizer
2
+ from flask import Flask, request, jsonify
3
+ import tensorflow as tf
4
+
5
+ app = Flask(__name__)
6
+
7
+ # Load Hugging Face model and tokenizer
8
+ tokenizer = AutoTokenizer.from_pretrained("Erfan11/Neuracraft", use_auth_token="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")
9
+ hf_model = AutoModel.from_pretrained("Erfan11/Neuracraft", use_auth_token="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")
10
+
11
+ # Load TensorFlow model
12
+ tf_model = tf.keras.models.load_model('path_to_your_tf_model.h5')
13
+
14
+ @app.route('/predict', methods=['POST'])
15
+ def predict():
16
+ data = request.get_json()
17
+
18
+ # Tokenize the input using Hugging Face's tokenizer
19
+ inputs = tokenizer(data["text"], return_tensors="pt")
20
+
21
+ # Make prediction with Hugging Face model
22
+ hf_outputs = hf_model(**inputs)
23
+
24
+ # Optionally: You can also add TensorFlow model predictions here, depending on what it’s used for.
25
+ # Assuming the TensorFlow model is used for something else like feature extraction
26
+ tf_outputs = tf_model.predict([data["text"]]) # Modify based on your input processing
27
+
28
+ return jsonify({
29
+ "hf_outputs": hf_outputs[0].tolist(), # Convert Hugging Face output to JSON serializable format
30
+ "tf_outputs": tf_outputs.tolist() # Convert TensorFlow output to JSON serializable format
31
+ })
32
+
33
+ if __name__ == '__main__':
34
+ app.run(debug=True)