Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,7 +33,6 @@ print(f"CLOUDFLARE_AUTH_TOKEN: {API_TOKEN[:5]}..." if API_TOKEN else "Not set")
|
|
33 |
MODELS = [
|
34 |
"mistralai/Mistral-7B-Instruct-v0.3",
|
35 |
"mistralai/Mixtral-8x7B-Instruct-v0.1",
|
36 |
-
"meta-llama/Meta-Llama-3.1-8B-Instruct",
|
37 |
"@cf/meta/llama-3.1-8b-instruct"
|
38 |
]
|
39 |
|
@@ -349,20 +348,26 @@ def get_response_from_pdf(query, model, num_calls=3, temperature=0.2):
|
|
349 |
{context_str}
|
350 |
Write a detailed and complete response that answers the following user question: '{query}'"""
|
351 |
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
):
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
|
367 |
def vote(data: gr.LikeData):
|
368 |
if data.liked:
|
|
|
33 |
MODELS = [
|
34 |
"mistralai/Mistral-7B-Instruct-v0.3",
|
35 |
"mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
|
36 |
"@cf/meta/llama-3.1-8b-instruct"
|
37 |
]
|
38 |
|
|
|
348 |
{context_str}
|
349 |
Write a detailed and complete response that answers the following user question: '{query}'"""
|
350 |
|
351 |
+
if model == "@cf/meta/llama-3.1-8b-instruct":
|
352 |
+
# Use Cloudflare API
|
353 |
+
for response in get_response_from_cloudflare(prompt, num_calls, temperature):
|
354 |
+
yield response
|
355 |
+
else:
|
356 |
+
# Use Hugging Face API
|
357 |
+
client = InferenceClient(model, token=huggingface_token)
|
358 |
+
|
359 |
+
response = ""
|
360 |
+
for i in range(num_calls):
|
361 |
+
for message in client.chat_completion(
|
362 |
+
messages=[{"role": "user", "content": prompt}],
|
363 |
+
max_tokens=1000,
|
364 |
+
temperature=temperature,
|
365 |
+
stream=True,
|
366 |
+
):
|
367 |
+
if message.choices and message.choices[0].delta and message.choices[0].delta.content:
|
368 |
+
chunk = message.choices[0].delta.content
|
369 |
+
response += chunk
|
370 |
+
yield response # Yield partial response
|
371 |
|
372 |
def vote(data: gr.LikeData):
|
373 |
if data.liked:
|