Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,7 +71,7 @@ async def fetch_response_from_sambanova(individual_history, model="Meta-Llama-3.
|
|
| 71 |
return None
|
| 72 |
|
| 73 |
@app.route('/chat', methods=['POST'])
|
| 74 |
-
def chat_bot():
|
| 75 |
data = request.json
|
| 76 |
sentences = data.get('sentences', [])
|
| 77 |
|
|
@@ -79,8 +79,6 @@ def chat_bot():
|
|
| 79 |
return jsonify({"error": "Input should be a list of sentences"}), 400
|
| 80 |
|
| 81 |
corrected_sentences = []
|
| 82 |
-
loop = asyncio.new_event_loop()
|
| 83 |
-
asyncio.set_event_loop(loop)
|
| 84 |
|
| 85 |
for sentence in sentences:
|
| 86 |
individual_history = [
|
|
@@ -89,13 +87,12 @@ def chat_bot():
|
|
| 89 |
]
|
| 90 |
|
| 91 |
# Fetch response from SambaNova API
|
| 92 |
-
corrected_sentence =
|
| 93 |
if corrected_sentence:
|
| 94 |
corrected_sentences.append(corrected_sentence)
|
| 95 |
else:
|
| 96 |
return jsonify({"error": "Failed to generate a response"}), 500
|
| 97 |
|
| 98 |
-
loop.close()
|
| 99 |
return jsonify({"response": corrected_sentences})
|
| 100 |
|
| 101 |
# Edge TTS function
|
|
@@ -131,4 +128,4 @@ async def tts_bot():
|
|
| 131 |
return jsonify({"error": "Failed to generate TTS audio"}), 500
|
| 132 |
|
| 133 |
if __name__ == '__main__':
|
| 134 |
-
app.run(host='0.0.0.0', port=5000)
|
|
|
|
| 71 |
return None
|
| 72 |
|
| 73 |
@app.route('/chat', methods=['POST'])
|
| 74 |
+
async def chat_bot():
|
| 75 |
data = request.json
|
| 76 |
sentences = data.get('sentences', [])
|
| 77 |
|
|
|
|
| 79 |
return jsonify({"error": "Input should be a list of sentences"}), 400
|
| 80 |
|
| 81 |
corrected_sentences = []
|
|
|
|
|
|
|
| 82 |
|
| 83 |
for sentence in sentences:
|
| 84 |
individual_history = [
|
|
|
|
| 87 |
]
|
| 88 |
|
| 89 |
# Fetch response from SambaNova API
|
| 90 |
+
corrected_sentence = await fetch_response_from_sambanova(individual_history)
|
| 91 |
if corrected_sentence:
|
| 92 |
corrected_sentences.append(corrected_sentence)
|
| 93 |
else:
|
| 94 |
return jsonify({"error": "Failed to generate a response"}), 500
|
| 95 |
|
|
|
|
| 96 |
return jsonify({"response": corrected_sentences})
|
| 97 |
|
| 98 |
# Edge TTS function
|
|
|
|
| 128 |
return jsonify({"error": "Failed to generate TTS audio"}), 500
|
| 129 |
|
| 130 |
if __name__ == '__main__':
|
| 131 |
+
app.run(host='0.0.0.0', port=5000, use_reloader=False)
|