Spaces:
Sleeping
Sleeping
Upload main.py
Browse files- app/main.py +5 -2
app/main.py
CHANGED
@@ -30,11 +30,14 @@ FIllm = Llama(model_path="/models/final-gemma2b_FI-Q8_0.gguf")
|
|
30 |
# )
|
31 |
# return output
|
32 |
|
|
|
|
|
|
|
33 |
def check_sentiment(text):
|
34 |
prompt = f'Analyze the sentiment of the tweet enclosed in square brackets, determine if it is positive or negative, and return the answer as the corresponding sentiment label "positive" or "negative" [{text}] ='
|
35 |
response = SAllm(prompt, max_tokens=3, stop=["\n"], echo=False, temperature=0.5)
|
36 |
# print(response)
|
37 |
-
result = response
|
38 |
if "positive" in result:
|
39 |
return "positive"
|
40 |
elif "negative" in result:
|
@@ -115,7 +118,7 @@ def ask_gemmaFinanceTH(
|
|
115 |
if prompt:
|
116 |
try:
|
117 |
print(f'Asking FI with the question "{prompt}"')
|
118 |
-
result = FIllm(prompt, max_tokens=max_new_tokens, temperature=temperature, stop=["###User:", "###Assistant:"], echo=False)
|
119 |
print(f"Result: {result}")
|
120 |
return FI_Response(answer=result, question=prompt)
|
121 |
except Exception as e:
|
|
|
30 |
# )
|
31 |
# return output
|
32 |
|
33 |
+
def extract_restext(response):
|
34 |
+
return response['choices'][0]['text'].strip()
|
35 |
+
|
36 |
def check_sentiment(text):
|
37 |
prompt = f'Analyze the sentiment of the tweet enclosed in square brackets, determine if it is positive or negative, and return the answer as the corresponding sentiment label "positive" or "negative" [{text}] ='
|
38 |
response = SAllm(prompt, max_tokens=3, stop=["\n"], echo=False, temperature=0.5)
|
39 |
# print(response)
|
40 |
+
result = extract_restext(response)
|
41 |
if "positive" in result:
|
42 |
return "positive"
|
43 |
elif "negative" in result:
|
|
|
118 |
if prompt:
|
119 |
try:
|
120 |
print(f'Asking FI with the question "{prompt}"')
|
121 |
+
result = extract_restext(FIllm(prompt, max_tokens=max_new_tokens, temperature=temperature, stop=["###User:", "###Assistant:"], echo=False))
|
122 |
print(f"Result: {result}")
|
123 |
return FI_Response(answer=result, question=prompt)
|
124 |
except Exception as e:
|