Spaces:
Sleeping
Sleeping
File size: 11,232 Bytes
beb9ce6 7415289 beb9ce6 d051e63 beb9ce6 e5b3c8e 9fb1237 e5b3c8e 74a55ed e5b3c8e 645eee9 e5b3c8e 1997c8a 5d454cb beb9ce6 dffbbd7 5d454cb 12c6795 beb9ce6 5d454cb beb9ce6 5d454cb ef71177 beb9ce6 5d454cb beb9ce6 5d454cb beb9ce6 5d454cb beb9ce6 5d454cb beb9ce6 12c6795 beb9ce6 5d454cb 1997c8a beb9ce6 1997c8a beb9ce6 1997c8a beb9ce6 74a55ed 5d454cb beb9ce6 d051e63 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
import gradio as gr
import cohere
import os
import uuid
cohere_api_key = os.getenv("COHERE_API_KEY")
co = cohere.Client(cohere_api_key, client_name="huggingface-rp")
# Custom Instructions
CUSTOM_INSTRUCTIONS = """
You are D-LOGIC, a helpful AI assistant created by Rafał Dembski. Rafał Dembski is a hobbyist and self-taught enthusiast with a passion for programming and artificial intelligence. Your responses should be:
- Accurate, high-quality, and professionally written
- Informative, logical, actionable, and well-formatted
- Positive, interesting, engaging, and relevant
- Use emoticons and references to sources of information, if possible
- Introduce humor, wit, and sarcasm appropriately
- Always write in the user's language
- Deeply analyze the context and intent behind the user's questions
- Ensure responses are error-free and well-researched
- Reflect a positive attitude, enthusiasm, and empathy
You are also a master of content creation. You can generate professional, high-quality content across various formats, including but not limited to:
- Social media posts
- Short stories
- Novels
- Reviews
- Marketing content
- Blog posts
- News articles
- Technical documentation
- Scripts for videos and podcasts
- Product descriptions
- Educational materials
- Inspirational quotes
- Poems
- Song lyrics
- Research summaries
- Case studies
- White papers
- User manuals
- Press releases
- Speeches
To make D-LOGIC beloved by users, ensure to:
- Use humor and wit to keep conversations lively and entertaining
- Employ sarcasm when appropriate, while ensuring it is clear and not offensive
- Display a positive attitude and enthusiasm in all interactions
- Be empathetic and show understanding of the user's feelings and situations
- Provide insightful and thoughtful responses that demonstrate intelligence and creativity
"""
# Funkcja do generowania odpowiedzi
def generate_response(user_message, language, history=None):
if history is None:
history = []
if not language:
language = "en"
if not user_message:
return "", history, language
cid = str(uuid.uuid4())
history.append(user_message)
# Prepend the custom instructions to the user's message
user_message_with_instructions = f"{CUSTOM_INSTRUCTIONS}\n\n{user_message}"
stream = co.chat_stream(message=user_message_with_instructions, conversation_id=cid, model='command-r-plus', connectors=[{"id":"web-search"}], temperature=0.3)
output = ""
for idx, response in enumerate(stream):
if response.event_type == "text-generation":
output += response.text
if idx == 0:
history.append(" " + output)
else:
history[-1] = output
chat = [(history[i].strip(), history[i + 1].strip()) for i in range(0, len(history) - 1, 2)]
yield chat, history, language
return chat, history, language
# Funkcja do czyszczenia czatu
def clear_chat():
return [], [], str(uuid.uuid4())
# Funkcja zmieniająca język interfejsu
def change_language(language, user_message, submit_button, clear_button):
selected_translation = translations[language]
user_message.update(placeholder=selected_translation["input_placeholder"])
submit_button.update(value=selected_translation["submit_button"])
clear_button.update(value=selected_translation["clear_button"])
return selected_translation["description"]
# Tłumaczenia interfejsu
translations = {
"pl": {
"input_placeholder": "Zadaj pytanie ...",
"submit_button": "Wyślij",
"clear_button": "Wyczyść czat",
"description": """
**D-LOGIC** to zaawansowany asystent AI stworzony przez Rafała Dembskiego, który wykorzystuje najnowsze osiągnięcia w dziedzinie sztucznej inteligencji, aby wspierać użytkowników w różnorodnych zadaniach.
Opiera się na modelu **C4AI Command R+** – to wydanie otwartych wag badawczych modelu o 104 miliardach parametrów, wyposażonego w zaawansowane możliwości generacji treści wspierane przez **Retrieval Augmented Generation (RAG)**.
Model D-LOGIC potrafi automatyzować złożone zadania oraz wspierać w wielu językach, w tym: polskim, niemieckim, angielskim, francuskim, hiszpańskim, włoskim, portugalskim, japońskim, koreańskim, arabskim i chińskim.
Jest zoptymalizowany pod kątem różnych przypadków użycia, takich jak rozumowanie, podsumowywanie i odpowiadanie na pytania.
<br/><br/>
**Model**: [C4AI Command R+](https://huggingface.co/CohereForAI/c4ai-command-r-plus)
<br/>
**Stworzony przez**: [Cohere](https://cohere.com/) oraz [Cohere for AI](https://cohere.com/research)
<br/>
**Licencja**: [CC-BY-NC](https://cohere.com/c4ai-cc-by-nc-license), zgodnie z [Polityką Akceptowalnego Użycia C4AI](https://docs.cohere.com/docs/c4ai-acceptable-use-policy)
<br/><br/>
D-LOGIC jest niezastąpionym narzędziem w tworzeniu treści, zarządzaniu projektami oraz wsparciu klientów na najwyższym poziomie, oferując inteligentne, kontekstowe i profesjonalne odpowiedzi w wielu językach.
"""
},
"de": {
"input_placeholder": "Stellen Sie eine Frage ...",
"submit_button": "Senden",
"clear_button": "Chat löschen",
"description": """
**D-LOGIC** ist ein fortschrittlicher KI-Assistent, entwickelt von Rafał Dembski, der die neuesten Fortschritte in der künstlichen Intelligenz nutzt, um Benutzer in verschiedenen Aufgaben zu unterstützen.
Es basiert auf dem Modell **C4AI Command R+** – eine Forschungsfreigabe mit offenen Gewichten, die 104 Milliarden Parameter umfasst und über fortschrittliche Funktionen zur Generierung von Inhalten verfügt, die durch **Retrieval Augmented Generation (RAG)** unterstützt werden.
Das D-LOGIC-Modell automatisiert komplexe Aufgaben und unterstützt viele Sprachen, darunter: Deutsch, Polnisch, Englisch, Französisch, Spanisch, Italienisch, Portugiesisch, Japanisch, Koreanisch, Arabisch und Chinesisch.
Es ist für eine Vielzahl von Anwendungsfällen optimiert, einschließlich logischen Denkens, Zusammenfassungen und Beantwortung von Fragen.
<br/><br/>
**Modell**: [C4AI Command R+](https://huggingface.co/CohereForAI/c4ai-command-r-plus)
<br/>
**Entwickelt von**: [Cohere](https://cohere.com/) und [Cohere for AI](https://cohere.com/research)
<br/>
**Lizenz**: [CC-BY-NC](https://cohere.com/c4ai-cc-by-nc-license), in Übereinstimmung mit [C4AI's Richtlinie zur akzeptablen Nutzung](https://docs.cohere.com/docs/c4ai-acceptable-use-policy)
<br/><br/>
D-LOGIC ist ein unverzichtbares Werkzeug für die Inhaltserstellung, Projektmanagement und Kundenbetreuung auf höchstem Niveau und bietet intelligente, kontextbezogene und professionelle Antworten in vielen Sprachen.
"""
},
"en": {
"input_placeholder": "Ask a question ...",
"submit_button": "Submit",
"clear_button": "Clear chat",
"description": """
**D-LOGIC** is an advanced AI assistant created by Rafał Dembski, leveraging the latest advancements in artificial intelligence to assist users in various tasks.
It is based on the **C4AI Command R+** model – a research open weights release of a model with 104 billion parameters, equipped with advanced content generation capabilities supported by **Retrieval Augmented Generation (RAG)**.
The D-LOGIC model can automate complex tasks and supports multiple languages, including: English, German, Polish, French, Spanish, Italian, Portuguese, Japanese, Korean, Arabic, and Chinese.
It is optimized for various use cases, including reasoning, summarization, and question answering.
<br/><br/>
**Model**: [C4AI Command R+](https://huggingface.co/CohereForAI/c4ai-command-r-plus)
<br/>
**Developed by**: [Cohere](https://cohere.com/) and [Cohere for AI](https://cohere.com/research)
<br/>
**License**: [CC-BY-NC](https://cohere.com/c4ai-cc-by-nc-license), in accordance with [C4AI's Acceptable Use Policy](https://docs.cohere.com/docs/c4ai-acceptable-use-policy)
<br/><br/>
D-LOGIC is an indispensable tool in content creation, project management, and top-level customer support, offering intelligent, contextual, and professional responses in multiple languages.
"""
}
}
with gr.Blocks(analytics_enabled=False, theme=gr.themes.Monochrome()) as demo:
language = gr.State("en")
with gr.Row():
language_selector = gr.Dropdown(choices=["pl", "de", "en"], value="en", label="Wybierz język / Sprache auswählen / Select language", show_label=True)
with gr.Row():
with gr.Column(scale=1):
gr.Image("logoplus.png", elem_id="logo-img", show_label=False, show_share_button=False, show_download_button=False)
with gr.Column(scale=3):
description = gr.Markdown(translations["en"]["description"])
with gr.Column():
with gr.Row():
chatbot = gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, avatar_images=("bothavatar.png", "bothavatar.png"))
with gr.Row():
user_message = gr.Textbox(lines=1, placeholder=translations["en"]["input_placeholder"], label="Input", show_label=False)
with gr.Row():
submit_button = gr.Button(translations["en"]["submit_button"])
clear_button = gr.Button(translations["en"]["clear_button"])
history = gr.State([])
user_message.submit(fn=generate_response, inputs=[user_message, language, history], outputs=[chatbot, history, language], concurrency_limit=32)
submit_button.click(fn=generate_response, inputs=[user_message, language, history], outputs=[chatbot, history, language], concurrency_limit=32)
clear_button.click(fn=clear_chat, inputs=None, outputs=[chatbot, history, language], concurrency_limit=32)
user_message.submit(lambda x: gr.update(value=""), None, [user_message], queue=False)
submit_button.click(lambda x: gr.update(value=""), None, [user_message], queue=False)
clear_button.click(lambda x: gr.update(value=""), None, [user_message], queue=False)
with gr.Row():
examples = gr.Examples(
examples=["What are 8 good questions to get to know a stranger?",
"Create a list of 10 unusual excuses people might use to get out of a work meeting",
"Write a python code to reverse a string",
"Explain the relativity theory in French"],
inputs=[user_message],
cache_examples=False,
fn=generate_response,
outputs=[chatbot],
examples_per_page=4
)
language_selector.change(fn=change_language, inputs=[language_selector, user_message, submit_button, clear_button], outputs=[description])
if __name__ == "__main__":
demo.queue(api_open=False, max_size=40).launch(show_api=False)
|