-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
67 lines (51 loc) · 2.11 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from flask import Flask, request, jsonify, render_template
from llmware.models import ModelCatalog
from llmware.agents import LLMfx
app = Flask(__name__)
# Load models
summary_model = ModelCatalog().load_model("slim-summary-tool", sample=False, temperature=0.0, max_output=200)
sentiment_model = LLMfx()
sentiment_model.load_tool("sentiment")
chatbot_model = ModelCatalog().load_model("bling-phi-3-gguf", sample=False, temperature=0.0)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/summarize', methods=['POST'])
def summarize():
data = request.get_json()
document_text = data['document_text']
model_name = data['model_name']
summary = summary_model.function_call(document_text)
return jsonify({'summary': summary['llm_response']})
@app.route('/analyze_sentiment', methods=['POST'])
def analyze_sentiment():
data = request.get_json()
if 'essay_text' not in data:
return jsonify({'error': 'Missing essay_text in request data'}), 400
essay_text = data['essay_text']
# Perform sentiment analysis
sentiment_result = sentiment_model.sentiment(essay_text)
# Extract sentiment and confidence score
sentiment_value = sentiment_result["llm_response"]["sentiment"]
confidence_level = sentiment_result["confidence_score"]
return jsonify({
'sentiment': sentiment_value,
'confidence': confidence_level
})
@app.route('/chat', methods=['POST'])
def chat():
data = request.get_json()
user_input = data['user_input']
model_name = data['model_name']
# Print user input and model name for debugging
print(f"User Input: {user_input}")
print(f"Model Name: {model_name}")
response = chatbot_model.inference(user_input)
# Print the raw response from the model
print(f"Model Response: {response}")
# Handle empty response
if not response:
return jsonify({'response': 'No response from model'}), 500
return jsonify({'response': response})
if __name__ == "__main__":
app.run(debug=True)