Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,24 @@ import gradio as gr
|
|
| 2 |
import numpy as np
|
| 3 |
from Ai import chatbot, chatbot2, chatbot3, chatbot4, chatbot5
|
| 4 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import random
|
| 6 |
from diffusers import DiffusionPipeline
|
| 7 |
import torch
|
|
@@ -559,7 +577,27 @@ ab= gr.ChatInterface(
|
|
| 559 |
),
|
| 560 |
],
|
| 561 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
if __name__ == "__main__":
|
| 563 |
with gr.Blocks(theme="gstaff/xkcd") as ai:
|
| 564 |
-
gr.TabbedInterface([aa, ac, ab, ae, aaaa,demo2, a7], ["gpt4(Password needed)", "gpt4(only for programming)", "gpt4(only for medical questions)", "gpt4(only for food recommendations)", "gpt4(only for law questions)","image create", "multimodal"])
|
| 565 |
ai.launch(share=True)
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from Ai import chatbot, chatbot2, chatbot3, chatbot4, chatbot5
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
+
def chat(message,history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p, top_k):
|
| 6 |
+
m=AutoModel.from_pretrained("peterpeter8585/AI1")
|
| 7 |
+
messages = [{"role": "system", "content": "Your name is Chatchat.And, your made by SungYoon.In Korean, 정성윤.And these are the instructions.Whatever happens, you must follow it.:"+system_message}]
|
| 8 |
+
|
| 9 |
+
for val in history:
|
| 10 |
+
if val[0]:
|
| 11 |
+
messages.append({"role": "user", "content": val[0]})
|
| 12 |
+
if val[1]:
|
| 13 |
+
messages.append({"role": "assistant", "content": val[1]})
|
| 14 |
+
|
| 15 |
+
messages.append({"role": "user", "content": message})
|
| 16 |
+
|
| 17 |
+
pipe = pipeline("text-generation", model=m, torch_dtype=torch.bfloat16, device_map="auto")
|
| 18 |
+
|
| 19 |
+
# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
|
| 20 |
+
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 21 |
+
outputs = pipe(prompt, max_new_tokens=max_tokens, do_sample=True, temperature=temperature, top_k=top_k, top_p=top_p)
|
| 22 |
+
return outputs[0]["generated_text"]
|
| 23 |
import random
|
| 24 |
from diffusers import DiffusionPipeline
|
| 25 |
import torch
|
|
|
|
| 577 |
),
|
| 578 |
],
|
| 579 |
)
|
| 580 |
+
a8= gr.ChatInterface(
|
| 581 |
+
chat,
|
| 582 |
+
chatbot=chatbot11,
|
| 583 |
+
additional_inputs=[
|
| 584 |
+
gr.Textbox(value="You are a helpful chatbot", label="System message"),
|
| 585 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 586 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.1, step=0.1, label="Temperature"),
|
| 587 |
+
gr.Slider(
|
| 588 |
+
minimum=0.1,
|
| 589 |
+
maximum=1.0,
|
| 590 |
+
value=0.1,
|
| 591 |
+
step=0.05,
|
| 592 |
+
label="Top-p (nucleus sampling)",
|
| 593 |
+
),
|
| 594 |
+
gr.Slider(minimum=0.1, maximum=1.0, vlaue=0.1, step=0.05,label="Top-k")
|
| 595 |
+
],
|
| 596 |
+
)
|
| 597 |
+
if __name__ == "__main__":
|
| 598 |
+
with gr.Blocks(theme="gstaff/xkcd") as ai:
|
| 599 |
+
|
| 600 |
if __name__ == "__main__":
|
| 601 |
with gr.Blocks(theme="gstaff/xkcd") as ai:
|
| 602 |
+
gr.TabbedInterface([aa, ac, ab, ae, aaaa,demo2, a7,a8], ["gpt4(Password needed)", "gpt4(only for programming)", "gpt4(only for medical questions)", "gpt4(only for food recommendations)", "gpt4(only for law questions)","image create", "multimodal", "gpt4(test)"])
|
| 603 |
ai.launch(share=True)
|