suayptalha commited on
Commit
77d3dbe
·
verified ·
1 Parent(s): 5d401f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -1,9 +1,12 @@
1
  import gradio as gr
2
  from gradio_client import Client, handle_file
 
3
 
4
- # Moondream2 ve LLaMA API'lerine bağlanmak için Client'ları başlatıyoruz
5
  moondream_client = Client("vikhyatk/moondream2")
6
- llama_client = Client("goingyt/meta-llama-Llama-3.3-70B-Instruct")
 
 
7
 
8
  # Sohbet geçmişini tutmak için bir değişken
9
  history = []
@@ -28,13 +31,15 @@ def describe_image(image, user_message):
28
 
29
  # Sohbet geçmişini birleştirip tek bir mesaj olarak LLaMA'ya gönderiyoruz
30
  full_conversation = "\n".join(history)
31
- llama_result = llama_client.predict(
32
- message=full_conversation,
33
- api_name="/chat"
 
 
34
  )
35
 
36
  # Sonucu döndürüyoruz
37
- return description + "\n\nAssistant: " + llama_result
38
 
39
  # Sohbet fonksiyonu, resim yüklenip yüklenmediğine göre yönlendirecek
40
  def chat_or_image(image, user_message):
@@ -47,11 +52,13 @@ def chat_or_image(image, user_message):
47
  # Resim yoksa, direkt LLaMA'ya mesajı gönderiyoruz
48
  history.append(f"User: {user_message}")
49
  full_conversation = "\n".join(history)
50
- llama_result = llama_client.predict(
51
- message=full_conversation,
52
- api_name="/chat"
 
 
53
  )
54
- return llama_result
55
 
56
  # Gradio arayüzü
57
  demo = gr.Interface(
 
1
  import gradio as gr
2
  from gradio_client import Client, handle_file
3
+ from huggingface_hub import InferenceClient
4
 
5
+ # Moondream2 için Client kullanıyoruz
6
  moondream_client = Client("vikhyatk/moondream2")
7
+
8
+ # LLaMA için InferenceClient kullanıyoruz
9
+ llama_client = InferenceClient("meta-llama/Llama-3.3-70B-Instruct")
10
 
11
  # Sohbet geçmişini tutmak için bir değişken
12
  history = []
 
31
 
32
  # Sohbet geçmişini birleştirip tek bir mesaj olarak LLaMA'ya gönderiyoruz
33
  full_conversation = "\n".join(history)
34
+ llama_result = llama_client.chat_completion(
35
+ messages=[{"role": "user", "content": full_conversation}],
36
+ max_tokens=512, # Burada token sayısını belirleyebilirsiniz
37
+ temperature=0.7, # Sıcaklık parametresi
38
+ top_p=0.95 # Nucleus sampling için top_p parametresi
39
  )
40
 
41
  # Sonucu döndürüyoruz
42
+ return description + "\n\nAssistant: " + llama_result['choices'][0]['message']['content']
43
 
44
  # Sohbet fonksiyonu, resim yüklenip yüklenmediğine göre yönlendirecek
45
  def chat_or_image(image, user_message):
 
52
  # Resim yoksa, direkt LLaMA'ya mesajı gönderiyoruz
53
  history.append(f"User: {user_message}")
54
  full_conversation = "\n".join(history)
55
+ llama_result = llama_client.chat_completion(
56
+ messages=[{"role": "user", "content": full_conversation}],
57
+ max_tokens=512,
58
+ temperature=0.7,
59
+ top_p=0.95
60
  )
61
+ return llama_result['choices'][0]['message']['content']
62
 
63
  # Gradio arayüzü
64
  demo = gr.Interface(