mahin1234 commited on
Commit
8bbf013
·
verified ·
1 Parent(s): d696d19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -1,20 +1,23 @@
1
  import os
2
 
3
- # ১. requirements.txt আপডেট করা
4
  with open("requirements.txt", "w") as f:
5
  f.write("gradio\nhuggingface_hub\n")
6
 
7
- # ২. app.py আপডেট করা
8
  app_code = """
9
  import gradio as gr
10
  from huggingface_hub import InferenceClient
11
  import os
12
 
13
- # Get token from Hugging Face Space Secrets
14
  hf_token = os.getenv('HF_TOKEN')
15
 
16
- # Initialize client for mx-llms/BLM
17
- client = InferenceClient(token=hf_token, model='mx-llms/BLM')
 
 
 
18
 
19
  def respond(
20
  message,
@@ -26,6 +29,7 @@ def respond(
26
  ):
27
  messages = [{"role": "system", "content": system_message}]
28
 
 
29
  for h in history:
30
  messages.append(h)
31
 
@@ -33,7 +37,7 @@ def respond(
33
 
34
  response = ""
35
 
36
- # Using the token-based client for streaming
37
  for message in client.chat_completion(
38
  messages,
39
  max_tokens=max_tokens,
@@ -46,8 +50,8 @@ def respond(
46
  response += token
47
  yield response
48
 
49
- # Gradio UI setup
50
- chatbot = gr.ChatInterface(
51
  respond,
52
  additional_inputs=[
53
  gr.Textbox(value="You are BLM. Created by MD Mushfiqur Rahim.", label="System message"),
@@ -55,14 +59,16 @@ chatbot = gr.ChatInterface(
55
  gr.Slider(minimum=0.1, maximum=2.0, value=0.1, step=0.1, label="Temperature"),
56
  gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.05, label="Top-p"),
57
  ],
58
- type="messages"
 
 
59
  )
60
 
61
  if __name__ == '__main__':
62
- chatbot.launch()
63
  """
64
 
65
  with open("app.py", "w") as f:
66
  f.write(app_code)
67
 
68
- print("✅ app.py has been updated to use the HF_TOKEN secret!")
 
1
  import os
2
 
3
+ # ১. requirements.txt আপডেট করা (Inference Client এর জন্য)
4
  with open("requirements.txt", "w") as f:
5
  f.write("gradio\nhuggingface_hub\n")
6
 
7
+ # ২. app.py আপডেট করা (Public Access Version)
8
  app_code = """
9
  import gradio as gr
10
  from huggingface_hub import InferenceClient
11
  import os
12
 
13
+ # Space Settings-এর Secrets থেকে টোকেনটি নেবে
14
  hf_token = os.getenv('HF_TOKEN')
15
 
16
+ # মডেল আইডি
17
+ model_id = 'mx-llms/BLM'
18
+
19
+ # Client ইনিশিয়ালাইজ করা (এটি আপনার টোকেন ব্যবহার করে কাজ করবে)
20
+ client = InferenceClient(token=hf_token, model=model_id)
21
 
22
  def respond(
23
  message,
 
29
  ):
30
  messages = [{"role": "system", "content": system_message}]
31
 
32
+ # চ্যাট হিস্ট্রি যোগ করা
33
  for h in history:
34
  messages.append(h)
35
 
 
37
 
38
  response = ""
39
 
40
+ # ইনফারেন্স কল (স্ট্রিমিং সহ)
41
  for message in client.chat_completion(
42
  messages,
43
  max_tokens=max_tokens,
 
50
  response += token
51
  yield response
52
 
53
+ # Gradio চ্যাট ইন্টারফেস
54
+ demo = gr.ChatInterface(
55
  respond,
56
  additional_inputs=[
57
  gr.Textbox(value="You are BLM. Created by MD Mushfiqur Rahim.", label="System message"),
 
59
  gr.Slider(minimum=0.1, maximum=2.0, value=0.1, step=0.1, label="Temperature"),
60
  gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.05, label="Top-p"),
61
  ],
62
+ type="messages",
63
+ title="BLM AI Assistant",
64
+ description="Created by MD Mushfiqur Rahim. This assistant is ready to help everyone!"
65
  )
66
 
67
  if __name__ == '__main__':
68
+ demo.launch()
69
  """
70
 
71
  with open("app.py", "w") as f:
72
  f.write(app_code)
73
 
74
+ print("✅ Public access app.py created successfully!")