Mahmoud Amiri commited on
Commit
826d17a
·
1 Parent(s): b2f2152

Fix blank Space by calling demo.launch()

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -11,25 +11,19 @@ def respond(
11
  top_p,
12
  hf_token: gr.OAuthToken,
13
  ):
14
- """
15
- Uses the Hugging Face InferenceClient with a token (OAuth) to access the model.
16
- This works with any text-to-text model like BART, T5, Pegasus, etc.
17
- """
18
  client = InferenceClient(
19
  token=hf_token.token,
20
  model="Bocklitz-Lab/lit2vec-tldr-bart-model"
21
  )
22
 
23
- # Construct input text (optionally prepend system message)
24
  full_input = f"{system_message.strip()}\n\n{message.strip()}"
25
 
26
- # Generate full response in one call
27
  response = client.text_generation(
28
  full_input,
29
  max_new_tokens=max_tokens,
30
  temperature=temperature,
31
  top_p=top_p,
32
- stream=False # Set to True for token streaming
33
  )
34
 
35
  yield response
@@ -38,20 +32,21 @@ def respond(
38
  chatbot = gr.ChatInterface(
39
  respond,
40
  chatbot=gr.Chatbot(),
41
- textbox=gr.Textbox(placeholder="Enter text to summarize...", container=False, scale=7),
42
  additional_inputs=[
43
- gr.Textbox(value="Summarize the following scientific text.", label="System message"),
44
  gr.Slider(minimum=16, maximum=1024, value=256, step=8, label="Max new tokens"),
45
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
46
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
47
  ],
48
  )
49
 
50
- with gr.Blocks() as demo:
 
 
51
  with gr.Sidebar():
52
  gr.LoginButton()
53
  chatbot.render()
54
 
55
-
56
- if __name__ == "__main__":
57
- demo.launch()
 
11
  top_p,
12
  hf_token: gr.OAuthToken,
13
  ):
 
 
 
 
14
  client = InferenceClient(
15
  token=hf_token.token,
16
  model="Bocklitz-Lab/lit2vec-tldr-bart-model"
17
  )
18
 
 
19
  full_input = f"{system_message.strip()}\n\n{message.strip()}"
20
 
 
21
  response = client.text_generation(
22
  full_input,
23
  max_new_tokens=max_tokens,
24
  temperature=temperature,
25
  top_p=top_p,
26
+ stream=False
27
  )
28
 
29
  yield response
 
32
  chatbot = gr.ChatInterface(
33
  respond,
34
  chatbot=gr.Chatbot(),
35
+ textbox=gr.Textbox(placeholder="Paste abstract of a chemistry paper...", container=False, scale=7),
36
  additional_inputs=[
37
+ gr.Textbox(value="Summarize this chemistry paper abstract:", label="System message"),
38
  gr.Slider(minimum=16, maximum=1024, value=256, step=8, label="Max new tokens"),
39
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
40
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
41
  ],
42
  )
43
 
44
+ demo = gr.Blocks()
45
+
46
+ with demo:
47
  with gr.Sidebar():
48
  gr.LoginButton()
49
  chatbot.render()
50
 
51
+ # 👇 This MUST be called at the module level for Hugging Face Spaces to work
52
+ demo.launch()