Spaces:
Runtime error
Runtime error
Rename client.py to api.py
Browse files
api.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
class LlamaChatbot:
|
| 5 |
+
def __init__(self, model_name="meta-llama/Llama-3.2-7b"):
|
| 6 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
self.model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
def get_response(self, user_input: str, conversation_history: str) -> str:
|
| 10 |
+
# Combine user input with the conversation history
|
| 11 |
+
input_text = conversation_history + user_input + " "
|
| 12 |
+
|
| 13 |
+
inputs = self.tokenizer(input_text, return_tensors="pt")
|
| 14 |
+
outputs = self.model.generate(**inputs, max_length=150)
|
| 15 |
+
response = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 16 |
+
|
| 17 |
+
return response.strip()
|
client.py
DELETED
|
@@ -1,7 +0,0 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
|
| 3 |
-
response=requests.post(
|
| 4 |
-
"http://localhost:8000/essay/invoke",
|
| 5 |
-
json={'input':{'topic':"my best friend"}})
|
| 6 |
-
|
| 7 |
-
print(response.json()['output']['content'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|