Spaces:
Sleeping
Sleeping
HuggingFace-SK
commited on
Commit
·
468edda
1
Parent(s):
b4c3a62
add groq api
Browse files
app.py
CHANGED
|
@@ -7,35 +7,14 @@ from flask import Flask, jsonify, render_template, request, send_file
|
|
| 7 |
import base64
|
| 8 |
import numpy as np
|
| 9 |
import pytesseract
|
| 10 |
-
from
|
| 11 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 12 |
-
|
| 13 |
-
model_name = "microsoft/Phi-3-mini-4k-instruct"
|
| 14 |
-
|
| 15 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
-
model_name,
|
| 17 |
-
torch_dtype="auto",
|
| 18 |
-
device_map="auto"
|
| 19 |
-
)
|
| 20 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
pipe = pipeline(
|
| 24 |
-
"text-generation",
|
| 25 |
-
model=model,
|
| 26 |
-
tokenizer=tokenizer,
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
generation_args = {
|
| 30 |
-
"max_new_tokens": 500,
|
| 31 |
-
"return_full_text": False,
|
| 32 |
-
"temperature": 0.0,
|
| 33 |
-
"do_sample": False,
|
| 34 |
-
}
|
| 35 |
|
| 36 |
app = Flask(__name__)
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
|
|
@@ -79,10 +58,13 @@ def analyse():
|
|
| 79 |
{ "role": "user", "content": f"{item}: {text}" }
|
| 80 |
]
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
|
| 88 |
def data_uri_to_image(data_uri):
|
|
|
|
| 7 |
import base64
|
| 8 |
import numpy as np
|
| 9 |
import pytesseract
|
| 10 |
+
from groq import Groq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
app = Flask(__name__)
|
| 13 |
|
| 14 |
+
HF_API_KEY=os.getenv("HF_API_KEY")
|
| 15 |
+
print(HF_API_KEY)
|
| 16 |
+
client = Groq(api_key=HF_API_KEY)
|
| 17 |
+
print(client)
|
| 18 |
|
| 19 |
|
| 20 |
|
|
|
|
| 58 |
{ "role": "user", "content": f"{item}: {text}" }
|
| 59 |
]
|
| 60 |
|
| 61 |
+
completion = client.chat.completions.create(
|
| 62 |
+
model="llama3-8b-8192",
|
| 63 |
+
messages=messages,
|
| 64 |
+
max_tokens=500
|
| 65 |
+
)
|
| 66 |
+
print("LLM", str(completion.choices[0].message.content), " - done")
|
| 67 |
+
return str(completion.choices[0].message.content)
|
| 68 |
|
| 69 |
|
| 70 |
def data_uri_to_image(data_uri):
|