Spaces:
Runtime error
Runtime error
Commit
·
553aebf
1
Parent(s):
3fb3843
Update app.py
Browse files
app.py
CHANGED
@@ -45,24 +45,11 @@ def openai_chat(api_key, model, message):
|
|
45 |
|
46 |
# Define the chat function for Hugging Face API
|
47 |
def hf_chat(model_name, message):
|
48 |
-
# Load the model
|
49 |
-
|
50 |
-
model = transformers.AutoModelForCausalLM.from_pretrained(model_name)
|
51 |
-
|
52 |
-
# Encode the message using the model's tokenizer
|
53 |
-
input_ids = tokenizer.encode(message, return_tensors="pt")
|
54 |
|
55 |
# Generate a response from the model
|
56 |
-
|
57 |
-
input_ids=input_ids,
|
58 |
-
max_length=1024,
|
59 |
-
do_sample=True,
|
60 |
-
top_p=0.9,
|
61 |
-
top_k=0,
|
62 |
-
)
|
63 |
-
|
64 |
-
# Decode the response
|
65 |
-
bot_response = tokenizer.decode(output[0], skip_special_tokens=True)
|
66 |
|
67 |
return bot_response
|
68 |
|
|
|
45 |
|
46 |
# Define the chat function for Hugging Face API
|
47 |
def hf_chat(model_name, message):
|
48 |
+
# Load the model and tokenizer
|
49 |
+
model = transformers.pipeline("text2text-generation", model=model_name)
|
|
|
|
|
|
|
|
|
50 |
|
51 |
# Generate a response from the model
|
52 |
+
bot_response = model(message, max_length=1024, do_sample=True, temperature=0.7)[0]["generated_text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
return bot_response
|
55 |
|