ciyidogan commited on
Commit
2a16a45
·
verified ·
1 Parent(s): b5c1d21

Update fine_tune_inference_test.py

Browse files
Files changed (1) hide show
  1. fine_tune_inference_test.py +10 -22
fine_tune_inference_test.py CHANGED
@@ -2,9 +2,9 @@ import os
2
  import threading
3
  import uvicorn
4
  from fastapi import FastAPI
5
- from fastapi.responses import HTMLResponse
6
  from pydantic import BaseModel
7
- from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, TextGenerationPipeline
8
  from datasets import load_dataset
9
  from peft import PeftModel
10
  import torch
@@ -34,10 +34,10 @@ pipe = None # global text-generation pipeline
34
  class Message(BaseModel):
35
  user_input: str
36
 
37
- @app.get("/")
38
  def health():
39
- return JSONResponse(content={"status": "ok"})
40
-
41
  @app.get("/start", response_class=HTMLResponse)
42
  def root():
43
  return """
@@ -45,12 +45,12 @@ def root():
45
  <head><title>Fine-Tune Chat</title></head>
46
  <body>
47
  <h2>📘 Fine-tune Chat Test</h2>
48
- <textarea id="input" rows="4" cols="60" placeholder="Bir şeyler yaz..."></textarea><br><br>
49
- <button onclick="send()">Gönder</button>
50
- <pre id="output"></pre>
51
  <script>
52
  async function send() {
53
- const input = document.getElementById("input").value;
54
  const res = await fetch("/chat", {
55
  method: "POST",
56
  headers: { "Content-Type": "application/json" },
@@ -143,18 +143,6 @@ def setup_model():
143
  except Exception as e:
144
  log(f"❌ setup_model() sırasında hata oluştu: {e}")
145
 
146
- # ✅ Sağlık kontrolü
147
- @app.get("/health")
148
- def health():
149
- return {"status": "ok"}
150
-
151
- def run_health_server():
152
- try:
153
- log("🩺 Health check endpoint başlatılıyor...")
154
- uvicorn.run(app, host="0.0.0.0", port=7860)
155
- except Exception as e:
156
- log(f"❌ Health server başlatılamadı: {e}")
157
-
158
  # ✅ Uygulama başlangıcı
159
  threading.Thread(target=setup_model, daemon=True).start()
160
 
@@ -164,4 +152,4 @@ while True:
164
  import time
165
  time.sleep(60)
166
  except Exception as e:
167
- log(f"❌ Ana bekleme döngüsünde hata: {e}")
 
2
  import threading
3
  import uvicorn
4
  from fastapi import FastAPI
5
+ from fastapi.responses import HTMLResponse, JSONResponse
6
  from pydantic import BaseModel
7
+ from transformers import AutoTokenizer, AutoModelForCausalLM, TextGenerationPipeline
8
  from datasets import load_dataset
9
  from peft import PeftModel
10
  import torch
 
34
  class Message(BaseModel):
35
  user_input: str
36
 
37
+ @app.get("/health")
38
  def health():
39
+ return {"status": "ok"}
40
+
41
  @app.get("/start", response_class=HTMLResponse)
42
  def root():
43
  return """
 
45
  <head><title>Fine-Tune Chat</title></head>
46
  <body>
47
  <h2>📘 Fine-tune Chat Test</h2>
48
+ <textarea id=\"input\" rows=\"4\" cols=\"60\" placeholder=\"Bir şeyler yaz...\"></textarea><br><br>
49
+ <button onclick=\"send()\">Gönder</button>
50
+ <pre id=\"output\"></pre>
51
  <script>
52
  async function send() {
53
+ const input = document.getElementById(\"input\").value;
54
  const res = await fetch("/chat", {
55
  method: "POST",
56
  headers: { "Content-Type": "application/json" },
 
143
  except Exception as e:
144
  log(f"❌ setup_model() sırasında hata oluştu: {e}")
145
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  # ✅ Uygulama başlangıcı
147
  threading.Thread(target=setup_model, daemon=True).start()
148
 
 
152
  import time
153
  time.sleep(60)
154
  except Exception as e:
155
+ log(f"❌ Ana bekleme döngüsünde hata: {e}")