suayptalha commited on
Commit
3001d0c
·
verified ·
1 Parent(s): cc9d2fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -23,8 +23,8 @@ def describe_image(image, user_message):
23
  )
24
 
25
  description = result # Moondream2'den açıklama alıyoruz
26
- history.append({"role": "user", "content": [{"type": "text", "text": user_message}]})
27
- history.append({"role": "assistant", "content": [{"type": "text", "text": description}]})
28
 
29
  return description
30
 
@@ -33,13 +33,10 @@ def chat_with_text(user_message, max_new_tokens=250):
33
  global history
34
 
35
  # Kullanıcı mesajını history'ye ekliyoruz
36
- history.append({"role": "user", "content": [{"type": "text", "text": user_message}]})
37
 
38
  # Tüm geçmişi LLaMA'ya gönderiyoruz
39
- texts = [
40
- {"role": msg["role"], "content": " ".join([part["text"] for part in msg["content"]])}
41
- for msg in history
42
- ]
43
  llama_result = llama_client.chat_completion(
44
  messages=texts,
45
  max_tokens=max_new_tokens,
@@ -49,7 +46,7 @@ def chat_with_text(user_message, max_new_tokens=250):
49
 
50
  # Asistan cevabını alıyoruz ve history'ye ekliyoruz
51
  assistant_reply = llama_result["choices"][0]["message"]["content"]
52
- history.append({"role": "assistant", "content": [{"type": "text", "text": assistant_reply}]})
53
 
54
  return assistant_reply
55
 
@@ -70,7 +67,7 @@ demo = gr.ChatInterface(
70
  fn=bot_streaming,
71
  title="Multimodal Chat Assistant",
72
  additional_inputs=[
73
- gr.Image(label="Upload an image (optional)", type="pil", optional=True),
74
  gr.Slider(
75
  minimum=10,
76
  maximum=500,
 
23
  )
24
 
25
  description = result # Moondream2'den açıklama alıyoruz
26
+ history.append({"role": "user", "content": user_message})
27
+ history.append({"role": "assistant", "content": description})
28
 
29
  return description
30
 
 
33
  global history
34
 
35
  # Kullanıcı mesajını history'ye ekliyoruz
36
+ history.append({"role": "user", "content": user_message})
37
 
38
  # Tüm geçmişi LLaMA'ya gönderiyoruz
39
+ texts = [{"role": msg["role"], "content": msg["content"]} for msg in history]
 
 
 
40
  llama_result = llama_client.chat_completion(
41
  messages=texts,
42
  max_tokens=max_new_tokens,
 
46
 
47
  # Asistan cevabını alıyoruz ve history'ye ekliyoruz
48
  assistant_reply = llama_result["choices"][0]["message"]["content"]
49
+ history.append({"role": "assistant", "content": assistant_reply})
50
 
51
  return assistant_reply
52
 
 
67
  fn=bot_streaming,
68
  title="Multimodal Chat Assistant",
69
  additional_inputs=[
70
+ gr.Image(label="Upload an image (optional)", type="pil"), # Sadece resim
71
  gr.Slider(
72
  minimum=10,
73
  maximum=500,