Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,10 @@
|
|
| 1 |
-
import
|
| 2 |
-
from
|
| 3 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Inisialisasi HuggingFace client
|
| 6 |
client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
|
|
@@ -44,27 +48,35 @@ def process_json(json_input):
|
|
| 44 |
chat_history = chat_llama(chat_history)
|
| 45 |
return json.dumps(chat_history, indent=2), ""
|
| 46 |
|
| 47 |
-
|
| 48 |
-
def
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
import json
|
| 4 |
+
import univcron
|
| 5 |
+
from huggingface_hub import InferenceClient
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
|
| 9 |
# Inisialisasi HuggingFace client
|
| 10 |
client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
|
|
|
|
| 48 |
chat_history = chat_llama(chat_history)
|
| 49 |
return json.dumps(chat_history, indent=2), ""
|
| 50 |
|
| 51 |
+
@app.post("/chat_llama")
|
| 52 |
+
async def chat_llama_endpoint(request: Request):
|
| 53 |
+
data = await request.json()
|
| 54 |
+
chat_history = data.get('chat_history', [])
|
| 55 |
+
response = chat_llama(chat_history)
|
| 56 |
+
return JSONResponse(content=response)
|
| 57 |
+
|
| 58 |
+
@app.post("/chat_mem")
|
| 59 |
+
async def chat_mem_endpoint(request: Request):
|
| 60 |
+
data = await request.json()
|
| 61 |
+
message = data.get('message', '')
|
| 62 |
+
chat_history = data.get('chat_history', [])
|
| 63 |
+
response = chat_mem(message, chat_history)
|
| 64 |
+
return JSONResponse(content=response)
|
| 65 |
+
|
| 66 |
+
@app.post("/process_json")
|
| 67 |
+
async def process_json_endpoint(request: Request):
|
| 68 |
+
data = await request.json()
|
| 69 |
+
json_input = data.get('json_input', '')
|
| 70 |
+
response = process_json(json_input)
|
| 71 |
+
return JSONResponse(content=response)
|
| 72 |
+
|
| 73 |
+
def schedule_task():
|
| 74 |
+
print("Scheduled task is running")
|
| 75 |
|
| 76 |
+
# Tambahkan tugas terjadwal menggunakan univcron
|
| 77 |
+
univcron.every(10).seconds.do(schedule_task)
|
| 78 |
|
| 79 |
+
if __name__ == "__main__":
|
| 80 |
+
import uvicorn
|
| 81 |
+
# Jalankan server FastAPI
|
| 82 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|