gtani commited on
Commit
5670c86
Β·
verified Β·
1 Parent(s): abb86f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +113 -113
app.py CHANGED
@@ -1,138 +1,138 @@
1
- import gradio as gr
2
- from bedrock_client import bedrock_llm
3
- from langchain.schema import SystemMessage, HumanMessage, AIMessage
4
- import os
5
- from distutils.util import strtobool
6
 
7
 
8
- MULTIMODAL = os.environ.get("MULTIMODAL", "false")
9
 
10
- # 1) convert common truthy/falsy strings to bool
11
- try:
12
- MULTIMODAL = bool(strtobool(MULTIMODAL))
13
- except ValueError:
14
- # catch unrecognized values
15
- print(f"Invalid MULTIMODAL value: Use true/false, 1/0, yes/no.")
16
 
17
- AUTHS = [(os.environ.get('USER'), os.environ.get('PW'))]
18
 
19
- SYSTEM_PROMPT = os.environ.get('SYSTEM_PROMPT', '')
20
 
21
 
22
- def chat(message, history):
23
 
24
- # 1) start with the system prompt
25
- history_langchain_format: list = [SystemMessage(content=SYSTEM_PROMPT)]
26
 
27
- # 2) replay the user/assistant turns
28
- for msg in history:
29
- if msg["role"] == "user":
30
- history_langchain_format.append(HumanMessage(content=msg["content"]))
31
- elif msg["role"] == "assistant":
32
- history_langchain_format.append(AIMessage(content=msg["content"]))
33
 
34
- # 3) append the new user message
35
- history_langchain_format.append(HumanMessage(content=message))
36
 
37
- stream =bedrock_llm.stream(history_langchain_format)
38
 
39
- full = next(stream)
40
 
41
- for chunk in stream:
42
- full +=chunk
43
- yield full.content
44
 
45
 
46
- with gr.Blocks(css_paths=["static/deval.css"],theme = gr.themes.Default(primary_hue="blue", secondary_hue="yellow"),) as demo:
47
- # ── Logo + Header + Logout ────────────────────────────────
48
 
49
 
50
- with gr.Row():
51
- with gr.Column(scale=1):
52
- gr.Image(
53
- value="static/logo.png",
54
- height=50,
55
- show_label=False,
56
- interactive=False,
57
- show_download_button=False,
58
- show_fullscreen_button=False,
59
- elem_id="logo-primary", # matches the CSS above
60
- )
61
- with gr.Column(scale=10):
62
- gr.Markdown(
63
- "# DEvalBot\n\n"
64
- "**Hinweis:** Bitte gebe keine vertraulichen Informationen ein. "
65
- "Dazu zΓ€hlen u.a. sensible personenbezogene Daten, institutsinterne "
66
- "Informationen oder Dokumente, unverΓΆffentlichte Berichtsinhalte, "
67
- "vertrauliche Informationen oder Dokumente externer Organisationen "
68
- "sowie sensible erhobene Daten (wie etwa Interviewtranskripte).", elem_id="header-text"
69
- )
70
 
71
- # inject auto-reload script
72
- gr.HTML(
73
- """
74
- <script>
75
- // Reload the page after 1 minutes (300 000 ms)
76
- setTimeout(() => {
77
- window.location.reload();
78
- }, 1000);
79
- </script>
80
- """
81
- )
82
- gr.ChatInterface(
83
- chat,
84
- type="messages",
85
- multimodal=MULTIMODAL,
86
- editable=True,
87
- concurrency_limit=20,
88
- save_history=True,
89
- )
90
 
91
 
92
 
93
- demo.queue().launch(auth=AUTHS, share=True, ssr_mode=False)
94
 
95
- # import gradio as gr
96
 
97
- # # Replace this with your target URL
98
- # NEW_PAGE_URL = "https://huggingface.co/spaces/evaluatorhub42/DEvalbot"
99
 
100
- # with gr.Blocks(css_paths=["static/deval.css"], theme=gr.themes.Default(primary_hue="blue", secondary_hue="yellow")) as demo:
101
- # with gr.Row():
102
- # with gr.Column(scale=1):
103
- # gr.Image(
104
- # value="static/logo.png",
105
- # height=50,
106
- # show_label=False,
107
- # interactive=False,
108
- # show_download_button=False,
109
- # show_fullscreen_button=False,
110
- # elem_id="logo-primary",
111
- # )
112
- # with gr.Column(scale=10):
113
- # pass # Empty space or title if needed
114
 
115
- # with gr.Row():
116
- # gr.HTML(
117
- # f"""
118
- # <div style="
119
- # display: flex;
120
- # justify-content: center;
121
- # align-items: center;
122
- # flex-direction: column;
123
- # height: 60vh;
124
- # text-align: center;
125
- # color: white;
126
- # font-size: 2rem;
127
- # ">
128
- # <p style="margin: 0.5em 0; color: white; font-weight: bold;">⚠️ DEvalBot has moved!</p>
129
- # <p style="margin: 0.5em 0; color: white;">Please visit the new page:</p>
130
- # <p style="margin: 0.5em 0;">
131
- # <a href="{NEW_PAGE_URL}" style="color: white; font-weight: bold; text-decoration: underline;">
132
- # {NEW_PAGE_URL}
133
- # </a>
134
- # </p>
135
- # </div>
136
- # """
137
- # )
138
- # demo.launch()
 
1
+ # import gradio as gr
2
+ # from bedrock_client import bedrock_llm
3
+ # from langchain.schema import SystemMessage, HumanMessage, AIMessage
4
+ # import os
5
+ # from distutils.util import strtobool
6
 
7
 
8
+ # MULTIMODAL = os.environ.get("MULTIMODAL", "false")
9
 
10
+ # # 1) convert common truthy/falsy strings to bool
11
+ # try:
12
+ # MULTIMODAL = bool(strtobool(MULTIMODAL))
13
+ # except ValueError:
14
+ # # catch unrecognized values
15
+ # print(f"Invalid MULTIMODAL value: Use true/false, 1/0, yes/no.")
16
 
17
+ # AUTHS = [(os.environ.get('USER'), os.environ.get('PW'))]
18
 
19
+ # SYSTEM_PROMPT = os.environ.get('SYSTEM_PROMPT', '')
20
 
21
 
22
+ # def chat(message, history):
23
 
24
+ # # 1) start with the system prompt
25
+ # history_langchain_format: list = [SystemMessage(content=SYSTEM_PROMPT)]
26
 
27
+ # # 2) replay the user/assistant turns
28
+ # for msg in history:
29
+ # if msg["role"] == "user":
30
+ # history_langchain_format.append(HumanMessage(content=msg["content"]))
31
+ # elif msg["role"] == "assistant":
32
+ # history_langchain_format.append(AIMessage(content=msg["content"]))
33
 
34
+ # # 3) append the new user message
35
+ # history_langchain_format.append(HumanMessage(content=message))
36
 
37
+ # stream =bedrock_llm.stream(history_langchain_format)
38
 
39
+ # full = next(stream)
40
 
41
+ # for chunk in stream:
42
+ # full +=chunk
43
+ # yield full.content
44
 
45
 
46
+ # with gr.Blocks(css_paths=["static/deval.css"],theme = gr.themes.Default(primary_hue="blue", secondary_hue="yellow"),) as demo:
47
+ # # ── Logo + Header + Logout ────────────────────────────────
48
 
49
 
50
+ # with gr.Row():
51
+ # with gr.Column(scale=1):
52
+ # gr.Image(
53
+ # value="static/logo.png",
54
+ # height=50,
55
+ # show_label=False,
56
+ # interactive=False,
57
+ # show_download_button=False,
58
+ # show_fullscreen_button=False,
59
+ # elem_id="logo-primary", # matches the CSS above
60
+ # )
61
+ # with gr.Column(scale=10):
62
+ # gr.Markdown(
63
+ # "# DEvalBot\n\n"
64
+ # "**Hinweis:** Bitte gebe keine vertraulichen Informationen ein. "
65
+ # "Dazu zΓ€hlen u.a. sensible personenbezogene Daten, institutsinterne "
66
+ # "Informationen oder Dokumente, unverΓΆffentlichte Berichtsinhalte, "
67
+ # "vertrauliche Informationen oder Dokumente externer Organisationen "
68
+ # "sowie sensible erhobene Daten (wie etwa Interviewtranskripte).", elem_id="header-text"
69
+ # )
70
 
71
+ # # inject auto-reload script
72
+ # gr.HTML(
73
+ # """
74
+ # <script>
75
+ # // Reload the page after 1 minutes (300 000 ms)
76
+ # setTimeout(() => {
77
+ # window.location.reload();
78
+ # }, 1000);
79
+ # </script>
80
+ # """
81
+ # )
82
+ # gr.ChatInterface(
83
+ # chat,
84
+ # type="messages",
85
+ # multimodal=MULTIMODAL,
86
+ # editable=True,
87
+ # concurrency_limit=20,
88
+ # save_history=True,
89
+ # )
90
 
91
 
92
 
93
+ # demo.queue().launch(auth=AUTHS, share=True, ssr_mode=False)
94
 
95
+ import gradio as gr
96
 
97
+ # Replace this with your target URL
98
+ NEW_PAGE_URL = "https://huggingface.co/spaces/evaluatorhub42/DEvalbot"
99
 
100
+ with gr.Blocks(css_paths=["static/deval.css"], theme=gr.themes.Default(primary_hue="blue", secondary_hue="yellow")) as demo:
101
+ with gr.Row():
102
+ with gr.Column(scale=1):
103
+ gr.Image(
104
+ value="static/logo.png",
105
+ height=50,
106
+ show_label=False,
107
+ interactive=False,
108
+ show_download_button=False,
109
+ show_fullscreen_button=False,
110
+ elem_id="logo-primary",
111
+ )
112
+ with gr.Column(scale=10):
113
+ pass # Empty space or title if needed
114
 
115
+ with gr.Row():
116
+ gr.HTML(
117
+ f"""
118
+ <div style="
119
+ display: flex;
120
+ justify-content: center;
121
+ align-items: center;
122
+ flex-direction: column;
123
+ height: 60vh;
124
+ text-align: center;
125
+ color: white;
126
+ font-size: 2rem;
127
+ ">
128
+ <p style="margin: 0.5em 0; color: white; font-weight: bold;">⚠️ DEvalBot has moved!</p>
129
+ <p style="margin: 0.5em 0; color: white;">Please visit the new page:</p>
130
+ <p style="margin: 0.5em 0;">
131
+ <a href="{NEW_PAGE_URL}" style="color: white; font-weight: bold; text-decoration: underline;">
132
+ {NEW_PAGE_URL}
133
+ </a>
134
+ </p>
135
+ </div>
136
+ """
137
+ )
138
+ demo.launch()