srbmihaicode commited on
Commit
647defb
·
verified ·
1 Parent(s): 84efe31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -1,8 +1,14 @@
1
  from flask import Flask, request, jsonify
2
- import ollama
 
 
 
 
 
3
 
4
  app = Flask(__name__)
5
  DEFAULT_TEMPERATURE = 0.7
 
6
  DEFAULT_TOP_P = 0.95
7
 
8
  def generate_journal_suggestion(current_page):
@@ -12,13 +18,17 @@ def generate_journal_suggestion(current_page):
12
  Întrebarea ar trebui să încurajeze reflecția personală mai profundă, explorarea sentimentelor sau clarificarea obiectivelor."""
13
  )
14
 
15
- response = ollama.chat(
16
- model="llama3",
17
- messages=[{"role": "user", "content": suggestion_prompt}],
18
- options={"temperature": DEFAULT_TEMPERATURE, "top_p": DEFAULT_TOP_P}
 
 
 
 
19
  )
20
-
21
- return response["message"]["content"]
22
  except Exception as e:
23
  return f"Error: {str(e)}"
24
 
 
1
  from flask import Flask, request, jsonify
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ MODEL_NAME = "meta-llama/Llama-3.1-8B-Instruct"
5
+
6
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
7
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME).to("cpu")
8
 
9
  app = Flask(__name__)
10
  DEFAULT_TEMPERATURE = 0.7
11
+ DEFAULT_MAX_TOKENS = 150
12
  DEFAULT_TOP_P = 0.95
13
 
14
  def generate_journal_suggestion(current_page):
 
18
  Întrebarea ar trebui să încurajeze reflecția personală mai profundă, explorarea sentimentelor sau clarificarea obiectivelor."""
19
  )
20
 
21
+ input_ids = tokenizer(suggestion_prompt, return_tensors="pt").input_ids.to("cpu")
22
+
23
+ output_ids = model.generate(
24
+ input_ids,
25
+ max_length=DEFAULT_MAX_TOKENS,
26
+ temperature=DEFAULT_TEMPERATURE,
27
+ top_p=DEFAULT_TOP_P,
28
+ do_sample=True,
29
  )
30
+ suggestion_response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
31
+
32
  except Exception as e:
33
  return f"Error: {str(e)}"
34