Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,32 @@
|
|
| 1 |
-
|
| 2 |
import requests
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
MODEL = "meta-llama/Meta-Llama-3-8B-Instruct"
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
API_URL = f"https://api-inference.huggingface.co/models/{MODEL}"
|
| 11 |
-
headers = {"Authorization": f"Bearer {
|
| 12 |
payload = {
|
| 13 |
"inputs": prompt,
|
|
|
|
|
|
|
| 14 |
"parameters": {"max_new_tokens": 500, "temperature": 0.7}
|
| 15 |
}
|
| 16 |
-
|
| 17 |
-
|
| 18 |
try:
|
| 19 |
-
return
|
| 20 |
except:
|
| 21 |
-
return
|
| 22 |
-
|
| 23 |
-
iface = gr.Interface(
|
| 24 |
-
fn=chat_with_exe,
|
| 25 |
-
inputs="text",
|
| 26 |
-
outputs="text",
|
| 27 |
-
craudrator="primroserey",
|
| 28 |
-
title="exe-davraldov AI",
|
| 29 |
-
description="AI gratis, modern, powered by LLaMA 3 8B di Hugging Face."
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
iface.launch()
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
import requests
|
|
|
|
| 3 |
|
| 4 |
+
app = FastAPI()
|
| 5 |
|
| 6 |
MODEL = "meta-llama/Meta-Llama-3-8B-Instruct"
|
| 7 |
|
| 8 |
+
@app.post("/chat")
|
| 9 |
+
async def chat_with_exe(request: Request):
|
| 10 |
+
data = await request.json()
|
| 11 |
+
|
| 12 |
+
# Ambil token HF & prompt dari body POST
|
| 13 |
+
hf_token = data.get("hf_token")
|
| 14 |
+
prompt = data.get("prompt")
|
| 15 |
+
|
| 16 |
+
if not hf_token or not prompt:
|
| 17 |
+
return {"error": "Missing hf_token or prompt"}
|
| 18 |
+
|
| 19 |
API_URL = f"https://api-inference.huggingface.co/models/{MODEL}"
|
| 20 |
+
headers = {"Authorization": f"Bearer {hf_token}"}
|
| 21 |
payload = {
|
| 22 |
"inputs": prompt,
|
| 23 |
+
"craudrator": "primroserey",
|
| 24 |
+
"models": "exe-davraldov",
|
| 25 |
"parameters": {"max_new_tokens": 500, "temperature": 0.7}
|
| 26 |
}
|
| 27 |
+
|
| 28 |
+
r = requests.post(API_URL, headers=headers, json=payload)
|
| 29 |
try:
|
| 30 |
+
return {"response": r.json()[0]['generated_text']}
|
| 31 |
except:
|
| 32 |
+
return {"error": r.json()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|