amangoyal05 commited on
Commit
cbfaa55
·
verified ·
1 Parent(s): c0eade4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -12
app.py CHANGED
@@ -1,26 +1,41 @@
1
- import os
2
- from gradio_client import Client
3
  import gradio as gr
 
 
 
 
 
4
 
5
- HF_TOKEN = os.environ.get("HF_TOKEN")
6
- REPO_ID = os.environ.get("REPO_ID")
7
- client = Client(REPO_ID, hf_token=HF_TOKEN)
8
 
9
- def reply(ques, history):
10
- print(ques)
11
- result = client.predict(
12
- message=ques,
13
- api_name="/chat"
 
 
 
 
14
  )
15
- return result
 
 
 
 
 
 
16
 
17
  with gr.Blocks(title="Madhuram Model Chat") as demo:
18
  with gr.Column(elem_id="main-container"):
19
  gr.Markdown("# Madhuram Chat Interface", elem_classes="center-text")
 
20
  chatbot = gr.ChatInterface(
21
- fn=reply,
22
  type="messages"
23
  )
 
24
  gr.Markdown("*Disclaimer - This is a demo version of Madhuram. It may occasionally generate incorrect or incomplete responses. Please verify important information independently. The complete model will be available through our own playground where the missing features will be incorporated.*", elem_classes="disclaimer")
25
 
26
  demo.css = """
 
 
 
1
  import gradio as gr
2
+ import os
3
+ import torch, time
4
+ from huggingface_hub import hf_hub_download, snapshot_download, login
5
+ import sys
6
+ import gc
7
 
8
+ login(token=os.environ["HF_TOKEN"])
9
+ tokenizer = os.environ["TOKENIZER"]
10
+ repo_id = os.environ["REPO_ID"]
11
 
12
+ torch.set_num_threads(1)
13
+ if torch.cuda.is_available():
14
+ torch.backends.cudnn.benchmark = True
15
+
16
+ try:
17
+ generate_file = hf_hub_download(
18
+ repo_id=repo_id,
19
+ filename="gen.py",
20
+ token=os.environ["HF_TOKEN"]
21
  )
22
+ os.system(f"cp {generate_file} ./gen.py")
23
+ except Exception as e:
24
+ print(f"Error downloading files: {e}")
25
+ model_path = None
26
+
27
+ sys.path.append('.')
28
+ from gen import chat_interface
29
 
30
  with gr.Blocks(title="Madhuram Model Chat") as demo:
31
  with gr.Column(elem_id="main-container"):
32
  gr.Markdown("# Madhuram Chat Interface", elem_classes="center-text")
33
+
34
  chatbot = gr.ChatInterface(
35
+ fn=chat_interface,
36
  type="messages"
37
  )
38
+
39
  gr.Markdown("*Disclaimer - This is a demo version of Madhuram. It may occasionally generate incorrect or incomplete responses. Please verify important information independently. The complete model will be available through our own playground where the missing features will be incorporated.*", elem_classes="disclaimer")
40
 
41
  demo.css = """