Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 6 |
-
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
|
| 7 |
-
HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
r = requests.post(API_URL, headers=HEADERS, json=payload)
|
| 16 |
-
data = r.json()
|
| 17 |
-
|
| 18 |
-
# Eğer model yükleniyorsa
|
| 19 |
-
if isinstance(data, dict) and "error" in data:
|
| 20 |
-
return f"Model yükleniyor veya hata oluştu:\n{data['error']}"
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def chat_fn(message, history):
|
| 29 |
if history is None:
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import os
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
client = InferenceClient(
|
| 8 |
+
provider="hf-inference",
|
| 9 |
+
api_key=HF_TOKEN,
|
| 10 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
def query_mistral(prompt):
|
| 13 |
+
response = client.text_generation(
|
| 14 |
+
model="mistralai/Mistral-7B-Instruct-v0.2",
|
| 15 |
+
prompt=prompt,
|
| 16 |
+
max_new_tokens=300,
|
| 17 |
+
temperature=0.7,
|
| 18 |
+
)
|
| 19 |
+
return response
|
| 20 |
|
| 21 |
def chat_fn(message, history):
|
| 22 |
if history is None:
|