Update fine_tune_inference_test.py
Browse files- fine_tune_inference_test.py +26 -4
fine_tune_inference_test.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
import threading
|
3 |
import uvicorn
|
4 |
-
from fastapi import FastAPI, Request
|
5 |
from pydantic import BaseModel
|
6 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
7 |
from datasets import load_dataset
|
@@ -22,9 +22,31 @@ chat_history = []
|
|
22 |
class Message(BaseModel):
|
23 |
user_input: str
|
24 |
|
25 |
-
@app.get("/")
|
26 |
-
def
|
27 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
@app.post("/chat")
|
30 |
def chat(msg: Message):
|
|
|
1 |
import os
|
2 |
import threading
|
3 |
import uvicorn
|
4 |
+
from fastapi import FastAPI, Request, HTMLResponse
|
5 |
from pydantic import BaseModel
|
6 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
7 |
from datasets import load_dataset
|
|
|
22 |
class Message(BaseModel):
|
23 |
user_input: str
|
24 |
|
25 |
+
@app.get("/", response_class=HTMLResponse)
|
26 |
+
def root():
|
27 |
+
return """
|
28 |
+
<html>
|
29 |
+
<head><title>Fine-Tune Chat</title></head>
|
30 |
+
<body>
|
31 |
+
<h2>📘 Fine-tune Chat Test</h2>
|
32 |
+
<textarea id="input" rows="4" cols="60" placeholder="Bir şeyler yaz..."></textarea><br><br>
|
33 |
+
<button onclick="send()">Gönder</button>
|
34 |
+
<pre id="output"></pre>
|
35 |
+
<script>
|
36 |
+
async function send() {
|
37 |
+
const input = document.getElementById("input").value;
|
38 |
+
const res = await fetch("/chat", {
|
39 |
+
method: "POST",
|
40 |
+
headers: { "Content-Type": "application/json" },
|
41 |
+
body: JSON.stringify({ user_input: input })
|
42 |
+
});
|
43 |
+
const data = await res.json();
|
44 |
+
document.getElementById("output").innerText = data.answer || data.error || "Hata oluştu.";
|
45 |
+
}
|
46 |
+
</script>
|
47 |
+
</body>
|
48 |
+
</html>
|
49 |
+
"""
|
50 |
|
51 |
@app.post("/chat")
|
52 |
def chat(msg: Message):
|