bkaplan commited on
Commit
1b04089
·
verified ·
1 Parent(s): e29cb99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -1,32 +1,28 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Hugging Face model bilgileri
5
- MODEL_NAME = "bkaplan/MRL1" # Kendi model adınızı buraya yazın
6
  client = InferenceClient(model=MODEL_NAME)
7
 
8
  # Chatbot için cevap fonksiyonu
9
  def respond(message, chat_history):
10
  try:
11
- # Chat-completion formatında mesajlar gönderiliyor
12
  messages = [{"role": "system", "content": "Sen bir asistansın."}]
13
  for user_message, assistant_response in chat_history:
14
  messages.append({"role": "user", "content": user_message})
15
  messages.append({"role": "assistant", "content": assistant_response})
16
  messages.append({"role": "user", "content": message})
17
-
18
  # Hugging Face API çağrısı
19
- response = client.chat_completion(
20
- model=MODEL_NAME,
21
- messages=messages,
22
- max_new_tokens=512,
23
- temperature=0.7,
24
- top_p=0.95,
25
- stream=False,
26
  )
27
 
28
  # Gelen yanıtı işleme
29
- bot_message = response["choices"][0]["message"]["content"]
30
  chat_history.append((message, bot_message))
31
  return "", chat_history
32
  except Exception as e:
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # Hugging Face modeli
5
+ MODEL_NAME = "bkaplan/MRL1" # Kendi modelinizi buraya yazın
6
  client = InferenceClient(model=MODEL_NAME)
7
 
8
  # Chatbot için cevap fonksiyonu
9
  def respond(message, chat_history):
10
  try:
11
+ # Mesajları hazırlama
12
  messages = [{"role": "system", "content": "Sen bir asistansın."}]
13
  for user_message, assistant_response in chat_history:
14
  messages.append({"role": "user", "content": user_message})
15
  messages.append({"role": "assistant", "content": assistant_response})
16
  messages.append({"role": "user", "content": message})
17
+
18
  # Hugging Face API çağrısı
19
+ response = client.chat(
20
+ inputs=messages,
21
+ parameters={"max_length": 512, "temperature": 0.7, "top_p": 0.95}
 
 
 
 
22
  )
23
 
24
  # Gelen yanıtı işleme
25
+ bot_message = response["generated_text"]
26
  chat_history.append((message, bot_message))
27
  return "", chat_history
28
  except Exception as e: