Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import pandas as pd
|
2 |
import torch
|
3 |
from sentence_transformers import SentenceTransformer, util
|
@@ -6,6 +7,8 @@ import json
|
|
6 |
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoModelForSequenceClassification
|
7 |
import spaces
|
8 |
|
|
|
|
|
9 |
# Ensure you have GPU support
|
10 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
11 |
|
@@ -50,7 +53,7 @@ def generate_response(query):
|
|
50 |
if intent == 0: # Handle intent 0 (e.g., informational query)
|
51 |
input_text = f"Document: {relevant_doc}\n\nQuestion: {query}\n\nAnswer:"
|
52 |
inputs = tokenizer(input_text, return_tensors="pt").to(device)
|
53 |
-
outputs = model_response.generate(inputs["input_ids"], max_length=
|
54 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
55 |
elif intent == 1: # Handle intent 1 (e.g., opinion-based query)
|
56 |
# Generate a response based on the detected intent
|
|
|
1 |
+
import os
|
2 |
import pandas as pd
|
3 |
import torch
|
4 |
from sentence_transformers import SentenceTransformer, util
|
|
|
7 |
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoModelForSequenceClassification
|
8 |
import spaces
|
9 |
|
10 |
+
CUDA_LAUNCH_BLOCKING=1
|
11 |
+
|
12 |
# Ensure you have GPU support
|
13 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
14 |
|
|
|
53 |
if intent == 0: # Handle intent 0 (e.g., informational query)
|
54 |
input_text = f"Document: {relevant_doc}\n\nQuestion: {query}\n\nAnswer:"
|
55 |
inputs = tokenizer(input_text, return_tensors="pt").to(device)
|
56 |
+
outputs = model_response.generate(inputs["input_ids"], max_length=150)
|
57 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
58 |
elif intent == 1: # Handle intent 1 (e.g., opinion-based query)
|
59 |
# Generate a response based on the detected intent
|