FardinHash commited on
Commit
2c073f5
β€’
1 Parent(s): da94297

released bot

Browse files
Files changed (1) hide show
  1. app.py +108 -59
app.py CHANGED
@@ -1,63 +1,112 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- """
5
- 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
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
-
9
-
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
-
20
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
-
26
- messages.append({"role": "user", "content": message})
27
-
28
- response = ""
29
-
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
-
42
- """
43
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
44
- """
45
- demo = gr.ChatInterface(
46
- respond,
47
- additional_inputs=[
48
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
49
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
50
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
51
- gr.Slider(
52
- minimum=0.1,
53
- maximum=1.0,
54
- value=0.95,
55
- step=0.05,
56
- label="Top-p (nucleus sampling)",
57
- ),
58
- ],
59
  )
60
 
61
 
62
- if __name__ == "__main__":
63
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+
3
+ # Import modules from other files
4
+ from bot import chatbot, model_inference, BOT_AVATAR, EXAMPLES, model_selector, decoding_strategy, temperature, max_new_tokens, repetition_penalty, top_p
5
+ from voice import respond
6
+ from chat import videochat
7
+
8
+ # Define Gradio theme
9
+ theme = gr.themes.Soft(
10
+ primary_hue="blue",
11
+ secondary_hue="orange",
12
+ neutral_hue="gray",
13
+ font=[gr.themes.GoogleFont('Libre Franklin'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif']
14
+ ).set(
15
+ body_background_fill_dark="#111111",
16
+ block_background_fill_dark="#111111",
17
+ block_border_width="1px",
18
+ block_title_background_fill_dark="#1e1c26",
19
+ input_background_fill_dark="#292733",
20
+ button_secondary_background_fill_dark="#24212b",
21
+ border_color_primary_dark="#343140",
22
+ background_fill_secondary_dark="#111111",
23
+ color_accent_soft_dark="transparent"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  )
25
 
26
 
27
+ # Chat interface block
28
+ with gr.Blocks(
29
+ fill_height=True,
30
+ css=""".gradio-container .avatar-container {height: 40px width: 40px !important;} #duplicate-button {margin: auto; color: white; background: #f1a139; border-radius: 100vh; margin-top: 2px; margin-bottom: 2px;}""",
31
+ ) as chat:
32
+ gr.Markdown("# Image Chat, Image Generation, Image classification and Normal Chat")
33
+ with gr.Row(elem_id="model_selector_row"):
34
+ # model_selector defined in chatbot.py
35
+ pass
36
+ # decoding_strategy, temperature, top_p defined in chatbot.py
37
+ decoding_strategy.change(
38
+ fn=lambda selection: gr.Slider(
39
+ visible=(
40
+ selection
41
+ in [
42
+ "contrastive_sampling",
43
+ "beam_sampling",
44
+ "Top P Sampling",
45
+ "sampling_top_k",
46
+ ]
47
+ )
48
+ ),
49
+ inputs=decoding_strategy,
50
+ outputs=temperature,
51
+ )
52
+ decoding_strategy.change(
53
+ fn=lambda selection: gr.Slider(visible=(selection in ["Top P Sampling"])),
54
+ inputs=decoding_strategy,
55
+ outputs=top_p,
56
+ )
57
+ gr.ChatInterface(
58
+ fn=model_inference,
59
+ chatbot=chatbot,
60
+ examples=EXAMPLES,
61
+ multimodal=True,
62
+ cache_examples=False,
63
+ additional_inputs=[
64
+ model_selector,
65
+ decoding_strategy,
66
+ temperature,
67
+ max_new_tokens,
68
+ repetition_penalty,
69
+ top_p,
70
+ gr.Checkbox(label="Web Search", value=True),
71
+ ],
72
+ )
73
+
74
+ # Voice chat block
75
+ with gr.Blocks() as voice:
76
+ with gr.Row():
77
+ select = gr.Dropdown(['Nous Hermes Mixtral 8x7B DPO', 'Mixtral 8x7B', 'StarChat2 15b', 'Mistral 7B v0.3',
78
+ 'Phi 3 mini', 'Zephyr 7b'], value="Mistral 7B v0.3", label="Select Model")
79
+ seed = gr.Slider(
80
+ label="Seed",
81
+ minimum=0,
82
+ maximum=999999,
83
+ step=1,
84
+ value=0,
85
+ visible=False
86
+ )
87
+ input = gr.Audio(label="User", sources="microphone", type="filepath", waveform_options=False)
88
+ output = gr.Audio(label="AI", type="filepath",
89
+ interactive=False,
90
+ autoplay=True,
91
+ elem_classes="audio")
92
+ gr.Interface(
93
+ fn=respond,
94
+ inputs=[input, select, seed],
95
+ outputs=[output], api_name="translate", live=True)
96
+
97
+ # Live chat block
98
+ with gr.Blocks() as livechat:
99
+ gr.Interface(
100
+ fn=videochat,
101
+ inputs=[gr.Image(type="pil",sources="webcam", label="Upload Image"), gr.Textbox(label="Prompt", value="what he is doing")],
102
+ outputs=gr.Textbox(label="Answer")
103
+ )
104
+
105
+
106
+ # Main application block
107
+ with gr.Blocks(theme=theme, title="Open Source GPT-4o") as demo:
108
+ gr.Markdown("# GPT-4o")
109
+ gr.TabbedInterface([chat, voice, livechat], ['πŸ’¬ SuperChat','πŸ—£οΈ Voice Chat','πŸ“Έ Live Chat'])
110
+
111
+ demo.queue(max_size=300)
112
+ demo.launch()