update
Browse files
app.py
CHANGED
@@ -132,8 +132,11 @@ async def generate_text(request: RequestModel):
|
|
132 |
generated_text += chunk.choices[0].delta.content
|
133 |
|
134 |
return {"summary_text_2": generated_text}
|
135 |
-
@app.post("/
|
136 |
-
async def generate_text(
|
|
|
|
|
|
|
137 |
# Check file size
|
138 |
contents = await file.read()
|
139 |
file_size = len(contents)
|
@@ -161,11 +164,19 @@ async def generate_text(file: UploadFile = File(...)):
|
|
161 |
if len(text_to_generate.encode('utf-8')) > 5_000_000:
|
162 |
return {"error": "Generated text exceeds size limit even after sampling. Please reduce the data further."}
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
# Create the request for the API
|
165 |
try:
|
166 |
completion = client.chat.completions.create(
|
167 |
model="meta/llama-3.1-8b-instruct",
|
168 |
-
messages=[{"role": "user", "content":
|
169 |
temperature=0.2,
|
170 |
top_p=0.9,
|
171 |
stream=True
|
|
|
132 |
generated_text += chunk.choices[0].delta.content
|
133 |
|
134 |
return {"summary_text_2": generated_text}
|
135 |
+
@app.post("/analyse/")
|
136 |
+
async def generate_text(
|
137 |
+
period: str = Query(..., description="Choisissez entre 'semaine' ou 'mois'"),
|
138 |
+
file: UploadFile = File(...)):
|
139 |
+
|
140 |
# Check file size
|
141 |
contents = await file.read()
|
142 |
file_size = len(contents)
|
|
|
164 |
if len(text_to_generate.encode('utf-8')) > 5_000_000:
|
165 |
return {"error": "Generated text exceeds size limit even after sampling. Please reduce the data further."}
|
166 |
|
167 |
+
# Define the appropriate prompt based on the period (week or month)
|
168 |
+
if period == "semaine":
|
169 |
+
prompt = "Analyse des plaintes par semaine :\n\n"
|
170 |
+
elif period == "mois":
|
171 |
+
prompt = "Analyse des plaintes par mois :\n\n"
|
172 |
+
else:
|
173 |
+
return {"error": "Invalid period. Choose either 'semaine' or 'mois'."}
|
174 |
+
|
175 |
# Create the request for the API
|
176 |
try:
|
177 |
completion = client.chat.completions.create(
|
178 |
model="meta/llama-3.1-8b-instruct",
|
179 |
+
messages=[{"role": "user", "content": prompt + text_to_generate}],
|
180 |
temperature=0.2,
|
181 |
top_p=0.9,
|
182 |
stream=True
|