Update app.py
Browse files
app.py
CHANGED
@@ -3,61 +3,28 @@ from typing import Union
|
|
3 |
from fastapi import FastAPI
|
4 |
import asyncio
|
5 |
|
6 |
-
from fastapi import FastAPI, File, UploadFile
|
7 |
-
from fastapi.responses import HTMLResponse
|
8 |
-
import shutil
|
9 |
-
import os
|
10 |
from groq import Groq, AsyncGroq
|
11 |
|
12 |
-
import google.generativeai as genai
|
13 |
-
import os
|
14 |
-
|
15 |
-
genai.configure(api_key="AIzaSyBGhEOy-JYMzGtTcRjBjP51OGR168WKRFw")
|
16 |
-
|
17 |
-
|
18 |
client = AsyncGroq(
|
19 |
-
api_key="
|
20 |
)
|
21 |
|
22 |
SYSTEM_PROMPT = """
|
23 |
-
|
24 |
"""
|
25 |
|
26 |
app = FastAPI()
|
27 |
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
# )
|
36 |
-
# chat_completion = await client.chat.completions.create(
|
37 |
-
# messages=messages,
|
38 |
-
# model="llama3-70b-8192",
|
39 |
-
# )
|
40 |
-
# return chat_completion.choices[0].message.content
|
41 |
-
|
42 |
-
|
43 |
-
@app.get("/test")
|
44 |
-
def test():
|
45 |
-
return "Hello"
|
46 |
-
|
47 |
-
@app.post("/")
|
48 |
-
async def upload_image(file: UploadFile = File(...)):
|
49 |
-
os.makedirs("uploads", exist_ok=True)
|
50 |
-
|
51 |
-
file_location = f"uploads/{file.filename}"
|
52 |
-
with open(file_location, "wb") as buffer:
|
53 |
-
shutil.copyfileobj(file.file, buffer)
|
54 |
-
|
55 |
-
myfile = genai.upload_file(file_location)
|
56 |
-
|
57 |
-
model = genai.GenerativeModel("gemini-1.5-flash")
|
58 |
-
result = model.generate_content(
|
59 |
-
[myfile, "\n\n",
|
60 |
-
"Проверь работу на фото, дай координаты всех слов в формате OpenCV, где допущина ошибка, также дай координаты мест где нужна была запятая(квадратом)."]
|
61 |
)
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
3 |
from fastapi import FastAPI
|
4 |
import asyncio
|
5 |
|
|
|
|
|
|
|
|
|
6 |
from groq import Groq, AsyncGroq
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
client = AsyncGroq(
|
9 |
+
api_key="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",
|
10 |
)
|
11 |
|
12 |
SYSTEM_PROMPT = """
|
13 |
+
Ты ассистент, помогай людям!
|
14 |
"""
|
15 |
|
16 |
app = FastAPI()
|
17 |
|
18 |
|
19 |
+
@app.post("/get_response")
|
20 |
+
async def read_root(messages: list[dict]):
|
21 |
+
messages.insert(0, {
|
22 |
+
"role": "system",
|
23 |
+
"content": SYSTEM_PROMPT
|
24 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
)
|
26 |
+
chat_completion = await client.chat.completions.create(
|
27 |
+
messages=messages,
|
28 |
+
model="llama3-70b-8192",
|
29 |
+
)
|
30 |
+
return chat_completion.choices[0].message.content
|