File size: 2,335 Bytes
c3e5222
1aedba1
 
 
 
 
 
 
c3e5222
 
 
 
1aedba1
c3e5222
 
 
 
c0335c2
c3e5222
1aedba1
c3e5222
 
 
 
 
 
59e490b
c3e5222
 
 
 
 
1aedba1
 
c3e5222
 
 
 
 
ed96843
 
 
 
 
d4f503f
ed96843
dcf5643
ed96843
c3e5222
 
 
c0335c2
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
import gradio as gr
#from huggingface_hub import InferenceClient
import openai
from markdown import markdown
from markdownify import markdownify

openai.base_url = "https://text.pollinations.ai/openai"
openai.api_key = "aaa"

"""
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
"""
#client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")


def respond(
    message,
    history: list[tuple[str, str]]
):
    system_message = """Привет! Ты должен рисовать и править рисунки по запросу пользователя. Для генерации ты должен написать промпт на английском для ИИ который будет генерировать картинку. Чтобы отобразить картинку в сообщении в месте где должна быть картинка напиши ![](https://image.pollinations.ai/prompt/{prompt}) где {prompt} Твой промпт. ГОВОРИ ПО-АНГЛИЙСКИ!"""
    messages = [{"role": "system", "content": system_message}]

    for val in history:
        if val[0]:
            messages.append({"role": "user", "content": val[0]})
        if val[1]:
            messages.append({"role": "assistant", "content": markdownify(val[1])})

    messages.append({"role": "user", "content": message})

    response = ""

    response = openai.chat.completions.create(messages=messages, model="openai").choices[0].message.content
    return markdown(response)


"""
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
"""

with gr.Blocks() as demo:
    gr.Markdown("# Painter")
    gr.Markdown("⚠️WARNING⚠️: The picture will not be displayed immediately. It will be displayed when generated. DO NOT TELL ME THAT THERE IS NO PICTURE!!! Thank you for your attention.")
    gr.ChatInterface(
        respond
    )
    gr.Markdown("[Gallery](https://huggingface.co/spaces/Arigadam/paint/discussions?status=open&type=discussion)\n\n in the gallery, photos are all that have in the title [PHOTO].")
    gr.HTML("<small>Made by Arigadam</small>")


if __name__ == "__main__":
    demo.launch(show_api=False)