13ilguun commited on
Commit
74f320a
·
1 Parent(s): 15293dd

Update: Initialization

Browse files
Files changed (1) hide show
  1. app.py +36 -42
app.py CHANGED
@@ -1,57 +1,51 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
  import os
4
- from dotenv import load_dotenv
5
 
6
- load_dotenv()
7
-
8
- # Load model from Hugging Face Hub
9
- model_id = "VentureCircle/LaunchPad"
10
  token = os.getenv("huggingface_token")
11
-
12
- generator = pipeline(
13
- "text-generation",
14
- model=model_id,
15
- tokenizer=model_id,
16
- token=token
17
- )
18
-
19
- def respond(message, history, system_message, max_tokens, temperature, top_p):
20
- # Combine chat history and message into a single prompt
21
- chat_prompt = system_message + "\n\n"
22
  for user, assistant in history:
23
  if user:
24
- chat_prompt += f"User: {user}\n"
25
  if assistant:
26
- chat_prompt += f"LaunchPad: {assistant}\n"
27
- chat_prompt += f"User: {message}\nLaunchPad:"
28
-
29
- output = generator(
30
- chat_prompt,
31
- max_new_tokens=max_tokens,
 
 
32
  temperature=temperature,
33
  top_p=top_p,
34
- do_sample=True
35
- )
36
-
37
- # Extract response only (after "LaunchPad:")
38
- response_text = output[0]["generated_text"].split("LaunchPad:")[-1].strip()
39
- return response_text
40
-
41
- # System message configuration
42
- system_message = gr.State(
43
- "I am Bilguun, a third year software engineering student at McGill University and the founder of VentureCircle. "
44
- "VentureCircle is based in Montreal. "
45
- "I created this chatbot, LaunchPad, to help aspiring entrepreneurs achieve their goals. "
46
- "Your name is LaunchPad. "
47
- "LaunchPad is a friendly AI assistant designed to provide useful and supportive guidance for starting and growing a startup."
48
- )
49
 
50
- # Gradio interface
51
  demo = gr.ChatInterface(
52
- fn=respond,
53
  additional_inputs=[
54
- system_message,
 
 
 
 
 
 
 
 
 
55
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
56
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
57
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
  import os
 
4
 
 
 
 
 
5
  token = os.getenv("huggingface_token")
6
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=token)
7
+
8
+ def respond(
9
+ message,
10
+ history: list[tuple[str, str]],
11
+ system_message,
12
+ max_tokens,
13
+ temperature,
14
+ top_p,
15
+ ):
16
+ messages = [{"role": "system", "content": system_message}]
17
  for user, assistant in history:
18
  if user:
19
+ messages.append({"role": "user", "content": user})
20
  if assistant:
21
+ messages.append({"role": "assistant", "content": assistant})
22
+ messages.append({"role": "user", "content": message})
23
+
24
+ response = ""
25
+ for message in client.chat_completion(
26
+ messages,
27
+ max_tokens=max_tokens,
28
+ stream=True,
29
  temperature=temperature,
30
  top_p=top_p,
31
+ ):
32
+ token_piece = message.choices[0].delta.content
33
+ response += token_piece
34
+ yield response
 
 
 
 
 
 
 
 
 
 
 
35
 
 
36
  demo = gr.ChatInterface(
37
+ respond,
38
  additional_inputs=[
39
+ gr.Textbox(
40
+ value=(
41
+ "I am Bilguun, a third year software engineering student at McGill University and the founder of VentureCircle. "
42
+ "VentureCircle is based in Montreal. "
43
+ "I created this chatbot, LaunchPad, to help aspiring entrepreneurs achieve their goals. "
44
+ "Your name is LaunchPad. "
45
+ "LaunchPad is a friendly AI assistant designed to provide useful and supportive guidance for starting and growing a startup."
46
+ ),
47
+ label="System message"
48
+ ),
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(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),