alpdk1394 commited on
Commit
34112e1
1 Parent(s): a7acb3a

Try llama3

Browse files
Files changed (1) hide show
  1. app.py +62 -6
app.py CHANGED
@@ -62,12 +62,68 @@
62
  # if __name__ == "__main__":
63
  # demo.launch()
64
 
 
 
 
 
 
 
 
 
 
 
 
65
  import gradio as gr
66
 
67
- def echo(message, history):
68
- if not history:
69
- return message
70
- return str(history[-1][0] + history[-1][1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
- demo = gr.ChatInterface(fn=echo, examples=["hello", "hola", "merhaba"], title="Echo Bot")
73
- demo.launch()
 
62
  # if __name__ == "__main__":
63
  # demo.launch()
64
 
65
+ # import gradio as gr
66
+
67
+ # def echo(message, history):
68
+ # if not history:
69
+ # return message
70
+ # return str(history[-1][0] + history[-1][1])
71
+
72
+ # demo = gr.ChatInterface(fn=echo, examples=["hello", "hola", "merhaba"], title="Echo Bot")
73
+ # demo.launch()
74
+
75
+ from huggingface_hub import InferenceClient
76
  import gradio as gr
77
 
78
+ client = InferenceClient("meta-llama/Meta-Llama-3-8B")
79
+
80
+ def respond(
81
+ message,
82
+ history: list[tuple[str, str]],
83
+ system_message,
84
+ max_tokens,
85
+ temperature,
86
+ top_p,
87
+ ):
88
+ messages = [{"role": "system", "content": system_message}]
89
+
90
+ for val in history:
91
+ if val[0]:
92
+ messages.append({"role": "user", "content": val[0]})
93
+ if val[1]:
94
+ messages.append({"role": "assistant", "content": val[1]})
95
+
96
+ messages.append({"role": "user", "content": message})
97
+
98
+ response = ""
99
+
100
+ for message in client.chat_completion(
101
+ messages,
102
+ max_tokens=max_tokens,
103
+ stream=True,
104
+ temperature=temperature,
105
+ top_p=top_p,
106
+ ):
107
+ token = message.choices[0].delta.content
108
+
109
+ response += token
110
+ yield response
111
+
112
+ demo = gr.ChatInterface(
113
+ respond,
114
+ additional_inputs=[
115
+ gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
116
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
117
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
118
+ gr.Slider(
119
+ minimum=0.1,
120
+ maximum=1.0,
121
+ value=0.95,
122
+ step=0.05,
123
+ label="Top-p (nucleus sampling)",
124
+ ),
125
+ ],
126
+ )
127
 
128
+ if __name__ == "__main__":
129
+ demo.launch()