rafaldembski commited on
Commit
e5b3c8e
1 Parent(s): 5d454cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -11
app.py CHANGED
@@ -49,6 +49,48 @@ To make D-LOGIC beloved by users, ensure to:
49
  - Provide insightful and thoughtful responses that demonstrate intelligence and creativity
50
  """
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  # Tłumaczenia interfejsu i przykładów
53
  translations = {
54
  "pl": {
@@ -125,17 +167,6 @@ translations = {
125
  }
126
  }
127
 
128
- # Funkcja zmieniająca język interfejsu
129
- def change_language(language):
130
- selected_translation = translations[language]
131
- return (
132
- gr.update(placeholder=selected_translation["input_placeholder"]),
133
- gr.update(value=selected_translation["submit_button"]),
134
- gr.update(value=selected_translation["clear_button"]),
135
- selected_translation["examples"],
136
- selected_translation["description"]
137
- )
138
-
139
  with gr.Blocks(analytics_enabled=False, theme=gr.themes.Monochrome()) as demo:
140
  language = gr.State("en")
141
 
 
49
  - Provide insightful and thoughtful responses that demonstrate intelligence and creativity
50
  """
51
 
52
+ # Funkcja do generowania odpowiedzi
53
+ def generate_response(user_message, language, history=None):
54
+ if history is None:
55
+ history = []
56
+ if not language:
57
+ language = "en"
58
+ if not user_message:
59
+ return "", history, language
60
+
61
+ cid = str(uuid.uuid4())
62
+ history.append(user_message)
63
+
64
+ # Prepend the custom instructions to the user's message
65
+ user_message_with_instructions = f"{CUSTOM_INSTRUCTIONS}\n\n{user_message}"
66
+
67
+ stream = co.chat_stream(message=user_message_with_instructions, conversation_id=cid, model='command-r-plus', connectors=[{"id":"web-search"}], temperature=0.3)
68
+
69
+ output = ""
70
+ for idx, response in enumerate(stream):
71
+ if response.event_type == "text-generation":
72
+ output += response.text
73
+ if idx == 0:
74
+ history.append(" " + output)
75
+ else:
76
+ history[-1] = output
77
+
78
+ chat = [(history[i].strip(), history[i + 1].strip()) for i in range(0, len(history) - 1, 2)]
79
+ yield chat, history, language
80
+
81
+ return chat, history, language
82
+
83
+ # Funkcja zmieniająca język interfejsu
84
+ def change_language(language):
85
+ selected_translation = translations[language]
86
+ return (
87
+ gr.update(placeholder=selected_translation["input_placeholder"]),
88
+ gr.update(value=selected_translation["submit_button"]),
89
+ gr.update(value=selected_translation["clear_button"]),
90
+ selected_translation["examples"],
91
+ selected_translation["description"]
92
+ )
93
+
94
  # Tłumaczenia interfejsu i przykładów
95
  translations = {
96
  "pl": {
 
167
  }
168
  }
169
 
 
 
 
 
 
 
 
 
 
 
 
170
  with gr.Blocks(analytics_enabled=False, theme=gr.themes.Monochrome()) as demo:
171
  language = gr.State("en")
172