eliebak HF staff commited on
Commit
09cda1f
1 Parent(s): f1cb7b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -19
app.py CHANGED
@@ -6,7 +6,7 @@ import torch
6
  import spaces
7
 
8
  # Initialize the client with your model
9
- client = InferenceClient("karpathy/gpt2_1558M_final2_hf")
10
 
11
  default_system = 'You are a helpful assistant'
12
 
@@ -42,15 +42,21 @@ def modify_system_session(system):
42
  system = default_system
43
  return system, system, []
44
 
45
- def use_example_and_respond(example, history, system_message, max_tokens, temperature, top_p):
46
- return example, respond(example, history, system_message, max_tokens, temperature, top_p)
 
 
 
 
 
 
47
 
48
  # Define example prompts
49
  unicorn_example = "In a shocking finding, scientist discovered a herd of unicorns living in a remote, previously unexplored valley, in the Andes Mountains. Even more surprising to the researchers was the fact that the unicorns spoke perfect English."
50
  time_travel_example = "Explain the grandfather paradox in time travel and propose a potential resolution."
51
 
52
  with gr.Blocks() as demo:
53
- gr.Markdown("<h1 style='text-align: center;'>GPT-2 1.5B Chat Demo</h1>")
54
 
55
  with gr.Row():
56
  with gr.Column(scale=3):
@@ -59,7 +65,7 @@ with gr.Blocks() as demo:
59
  modify_system = gr.Button("🛠️ Set system prompt and clear history")
60
 
61
  system_state = gr.Textbox(value=default_system, visible=False)
62
- chatbot = gr.Chatbot(label='GPT-2 1.5B Chat')
63
  message = gr.Textbox(lines=1, label='Your message')
64
 
65
  with gr.Row():
@@ -82,23 +88,13 @@ with gr.Blocks() as demo:
82
  submit.click(respond, inputs=[message, chatbot, system_state, max_tokens, temperature, top_p], outputs=[chatbot])
83
  clear_history.click(fn=clear_session, inputs=[], outputs=[message, chatbot])
84
  modify_system.click(fn=modify_system_session, inputs=[system_input], outputs=[system_state, system_input, chatbot])
85
-
86
- # New event handlers for example prompts
87
- example1.click(
88
- fn=use_example_and_respond,
89
- inputs=[lambda: unicorn_example, chatbot, system_state, max_tokens, temperature, top_p],
90
- outputs=[message, chatbot]
91
- )
92
- example2.click(
93
- fn=use_example_and_respond,
94
- inputs=[lambda: time_travel_example, chatbot, system_state, max_tokens, temperature, top_p],
95
- outputs=[message, chatbot]
96
- )
97
 
98
  gr.Markdown(
99
  """
100
- ## About GPT-2 1.5B
101
- This is a large language model trained by OpenAI and fine-tuned by Andrej Karpathy. It's capable of generating human-like text based on the input it receives.
102
  """
103
  )
104
 
 
6
  import spaces
7
 
8
  # Initialize the client with your model
9
+ client = InferenceClient("karpathy/gpt2_1558M_final2_hf") # Replace with your model's name or endpoint
10
 
11
  default_system = 'You are a helpful assistant'
12
 
 
42
  system = default_system
43
  return system, system, []
44
 
45
+ def use_example(example):
46
+ return example
47
+
48
+ def set_unicorn_example():
49
+ return unicorn_example
50
+
51
+ def set_time_travel_example():
52
+ return time_travel_example
53
 
54
  # Define example prompts
55
  unicorn_example = "In a shocking finding, scientist discovered a herd of unicorns living in a remote, previously unexplored valley, in the Andes Mountains. Even more surprising to the researchers was the fact that the unicorns spoke perfect English."
56
  time_travel_example = "Explain the grandfather paradox in time travel and propose a potential resolution."
57
 
58
  with gr.Blocks() as demo:
59
+ gr.Markdown("<h1 style='text-align: center;'>LLM.C 1.5B Chat Demo (GPT-2 1.5B)</h1>")
60
 
61
  with gr.Row():
62
  with gr.Column(scale=3):
 
65
  modify_system = gr.Button("🛠️ Set system prompt and clear history")
66
 
67
  system_state = gr.Textbox(value=default_system, visible=False)
68
+ chatbot = gr.Chatbot(label='LLM.C Chat')
69
  message = gr.Textbox(lines=1, label='Your message')
70
 
71
  with gr.Row():
 
88
  submit.click(respond, inputs=[message, chatbot, system_state, max_tokens, temperature, top_p], outputs=[chatbot])
89
  clear_history.click(fn=clear_session, inputs=[], outputs=[message, chatbot])
90
  modify_system.click(fn=modify_system_session, inputs=[system_input], outputs=[system_state, system_input, chatbot])
91
+ example1.click(fn=set_unicorn_example, inputs=[], outputs=[message])
92
+ example2.click(fn=set_time_travel_example, inputs=[], outputs=[message])
 
 
 
 
 
 
 
 
 
 
93
 
94
  gr.Markdown(
95
  """
96
+ ## About LLM.C
97
+ some stuff about llmc
98
  """
99
  )
100