Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
-
|
3 |
-
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
4 |
import whisper
|
5 |
import os
|
6 |
import tempfile
|
@@ -12,13 +11,7 @@ app = Flask(__name__)
|
|
12 |
# Initialize Whisper model
|
13 |
whisper_model = whisper.load_model("small") # Renamed variable
|
14 |
|
15 |
-
# Initialize Emotion Classifier
|
16 |
-
classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
|
17 |
|
18 |
-
# Initialize NER pipeline
|
19 |
-
ner_tokenizer = AutoTokenizer.from_pretrained("dslim/bert-base-NER")
|
20 |
-
ner_model = AutoModelForTokenClassification.from_pretrained("dslim/bert-base-NER") # Renamed variable
|
21 |
-
ner_pipeline = pipeline("ner", model=ner_model, tokenizer=ner_tokenizer) # Renamed variable
|
22 |
|
23 |
|
24 |
@app.route('/transcribe', methods=['POST'])
|
@@ -47,36 +40,4 @@ def transcribe():
|
|
47 |
print("Error:", str(e)) # Log error for debugging
|
48 |
return jsonify({"error": "Internal Server Error", "details": str(e)}), 500
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
@app.route('/classify', methods=['POST'])
|
53 |
-
def classify():
|
54 |
-
try:
|
55 |
-
data = request.get_json()
|
56 |
-
if 'text' not in data:
|
57 |
-
return jsonify({"error": "Missing 'text' field"}), 400
|
58 |
-
|
59 |
-
text = data['text']
|
60 |
-
result = classifier(text)
|
61 |
-
return jsonify(result)
|
62 |
-
|
63 |
-
except Exception as e:
|
64 |
-
return jsonify({"error": str(e)}), 500
|
65 |
-
|
66 |
-
@app.route('/ner', methods=['POST'])
|
67 |
-
def ner_endpoint():
|
68 |
-
try:
|
69 |
-
data = request.get_json()
|
70 |
-
text = data.get("text", "")
|
71 |
-
|
72 |
-
# Use the renamed ner_pipeline
|
73 |
-
ner_results = ner_pipeline(text)
|
74 |
-
|
75 |
-
words_and_entities = [
|
76 |
-
{"word": result['word'], "entity": result['entity']}
|
77 |
-
for result in ner_results
|
78 |
-
]
|
79 |
-
|
80 |
-
return jsonify({"entities": words_and_entities})
|
81 |
-
except Exception as e:
|
82 |
-
return jsonify({"error": str(e)}), 500
|
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
+
|
|
|
3 |
import whisper
|
4 |
import os
|
5 |
import tempfile
|
|
|
11 |
# Initialize Whisper model
|
12 |
whisper_model = whisper.load_model("small") # Renamed variable
|
13 |
|
|
|
|
|
14 |
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
@app.route('/transcribe', methods=['POST'])
|
|
|
40 |
print("Error:", str(e)) # Log error for debugging
|
41 |
return jsonify({"error": "Internal Server Error", "details": str(e)}), 500
|
42 |
|
43 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|