Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import torch
|
4 |
+
import threading
|
5 |
+
from huggingface_hub import hf_hub_download, login
|
6 |
+
import sys
|
7 |
+
import gc
|
8 |
+
|
9 |
+
login(token=os.environ["HF_TOKEN"])
|
10 |
+
tokenizer = os.environ["TOKENIZER"]
|
11 |
+
repo_id = os.environ["REPO_ID"]
|
12 |
+
|
13 |
+
torch.set_num_threads(1)
|
14 |
+
if torch.cuda.is_available():
|
15 |
+
torch.backends.cudnn.benchmark = True
|
16 |
+
|
17 |
+
try:
|
18 |
+
generate_file = hf_hub_download(
|
19 |
+
repo_id=repo_id,
|
20 |
+
filename="gen.py",
|
21 |
+
token=os.environ["HF_TOKEN"]
|
22 |
+
)
|
23 |
+
os.system(f"cp {generate_file} ./gen.py")
|
24 |
+
|
25 |
+
except Exception as e:
|
26 |
+
print(f"Error downloading files: {e}")
|
27 |
+
model_path = None
|
28 |
+
|
29 |
+
sys.path.append('.')
|
30 |
+
from gen import chat_interface
|
31 |
+
|
32 |
+
|
33 |
+
with gr.Blocks(title="Madhuram Model Chat") as demo:
|
34 |
+
with gr.Column(elem_id="main-container"):
|
35 |
+
gr.Markdown("# Madhuram Chat Interface", elem_classes="center-text")
|
36 |
+
|
37 |
+
chatbot = gr.ChatInterface(
|
38 |
+
fn=chat_interface,
|
39 |
+
type="messages",
|
40 |
+
title="Madhuram AI Assistant",
|
41 |
+
description="Chat with the Madhuram language model",
|
42 |
+
theme="soft",
|
43 |
+
retry_btn=True,
|
44 |
+
undo_btn=True,
|
45 |
+
clear_btn=True,
|
46 |
+
)
|
47 |
+
|
48 |
+
gr.Markdown(
|
49 |
+
"*Disclaimer - This is a demo version of Madhuram. It may occasionally "
|
50 |
+
"generate incorrect or incomplete responses. Please verify important "
|
51 |
+
"information independently. The complete model will be available through "
|
52 |
+
"our own playground where the missing features will be incorporated.*",
|
53 |
+
elem_classes="disclaimer"
|
54 |
+
)
|
55 |
+
|
56 |
+
demo.css = """
|
57 |
+
#main-container {
|
58 |
+
max-width: 900px;
|
59 |
+
margin: 0 auto;
|
60 |
+
padding: 20px;
|
61 |
+
}
|
62 |
+
.center-text {
|
63 |
+
text-align: center;
|
64 |
+
margin-bottom: 30px;
|
65 |
+
}
|
66 |
+
.disclaimer {
|
67 |
+
text-align: center;
|
68 |
+
color: #666;
|
69 |
+
font-size: 0.9em;
|
70 |
+
margin-top: 30px;
|
71 |
+
padding: 15px;
|
72 |
+
background-color: #f8f9fa;
|
73 |
+
border-radius: 8px;
|
74 |
+
border-left: 4px solid #007bff;
|
75 |
+
}
|
76 |
+
"""
|
77 |
+
|
78 |
+
|
79 |
+
if __name__ == "__main__":
|
80 |
+
demo.launch()
|