gtani commited on
Commit
3295cdb
Β·
verified Β·
1 Parent(s): 366d7b7

Upload folder using huggingface_hub

Browse files
.DS_Store ADDED
Binary file (6.15 kB). View file
 
.gradio/certificate.pem ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
3
+ TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
4
+ cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
5
+ WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
6
+ ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
7
+ MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
8
+ h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
9
+ 0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
10
+ A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
11
+ T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
12
+ B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
13
+ B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv
14
+ KBds0pjBqAlkd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RR4Xq37Z0j4r7g1SgEEzwxA57d
30
+ emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
31
+ -----END CERTIFICATE-----
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
  title: DEvalbot
3
- emoji: πŸƒ
4
  colorFrom: yellow
5
- colorTo: gray
6
  sdk: gradio
7
  sdk_version: 5.34.2
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: DEvalbot
3
+ emoji: 🐠
4
  colorFrom: yellow
5
+ colorTo: red
6
  sdk: gradio
7
  sdk_version: 5.34.2
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
__pycache__/bedrock_client.cpython-310.pyc ADDED
Binary file (682 Bytes). View file
 
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from bedrock_client import bedrock_llm
3
+ from langchain.schema import SystemMessage, HumanMessage, AIMessage
4
+ import os
5
+
6
+
7
+ AUTHS = [(os.environ.get('USER'), os.environ.get('PW'))]
8
+
9
+ def chat(message, history):
10
+ # 3a) Build Bedrock input (with system prompt + raw dict‐history)
11
+ system_prompt = (
12
+ "Du bist DevalBot, ein konversationeller Assistent des Deutschen Evaluierungsinstituts "
13
+ "fΓΌr Entwicklungsbewertung (DEval). DEval bietet staatlichen und zivilgesellschaftlichen "
14
+ "Organisationen in der Entwicklungszusammenarbeit unabhΓ€ngige und wissenschaftlich fundierte "
15
+ "Evaluierungen. Deine Hauptsprache ist Deutsch; antworte daher standardmÀßig auf Deutsch. "
16
+ "Du kannst zudem bei statistischen Analysen und Programmierung in Stata und R unterstΓΌtzen."
17
+ )
18
+
19
+ # 1) start with the system prompt
20
+ history_langchain_format: list = [SystemMessage(content=system_prompt)]
21
+
22
+ # 2) replay the user/assistant turns
23
+ for msg in history:
24
+ if msg["role"] == "user":
25
+ history_langchain_format.append(HumanMessage(content=msg["content"]))
26
+ elif msg["role"] == "assistant":
27
+ history_langchain_format.append(AIMessage(content=msg["content"]))
28
+
29
+ # 3) append the new user message
30
+ history_langchain_format.append(HumanMessage(content=message))
31
+
32
+ stream =bedrock_llm.stream(history_langchain_format)
33
+ full = next(stream)
34
+ for chunk in stream:
35
+ full +=chunk
36
+ yield full.content
37
+
38
+
39
+ with gr.Blocks(css_paths=["static/deval.css"],theme = gr.themes.Default(primary_hue="blue", secondary_hue="yellow"),) as demo:
40
+ # ── Logo + Header + Logout ────────────────────────────────
41
+
42
+
43
+ with gr.Row():
44
+ with gr.Column(scale=1):
45
+ gr.Image(
46
+ value="static/logo.png",
47
+ height=50,
48
+ show_label=False,
49
+ interactive=False,
50
+ show_download_button=False,
51
+ show_fullscreen_button=False,
52
+ elem_id="logo-primary", # matches the CSS above
53
+ )
54
+ with gr.Column(scale=10):
55
+ gr.Markdown(
56
+ "# DEvalBot\n\n"
57
+ "**Hinweis:** Bitte gebe keine vertraulichen Informationen ein. "
58
+ "Dazu zΓ€hlen u.a. sensible personenbezogene Daten, institutsinterne "
59
+ "Informationen oder Dokumente, unverΓΆffentlichte Berichtsinhalte, "
60
+ "vertrauliche Informationen oder Dokumente externer Organisationen "
61
+ "sowie sensible erhobene Daten (wie etwa Interviewtranskripte).", elem_id="header-text"
62
+ )
63
+
64
+ #Hinweis: Bitte gebe keine vertraulichen Informationen ein. Dazu zΓ€hlen u.a. sensible personenbezogene Daten, institutsinterne Informationen oder Dokumente, unverΓΆffentlichte Berichtsinhalte, vertrauliche Informationen oder Dokumente externer Organisationen sowie sensible erhobene Daten (wie etwa Interviewtranskripte).
65
+ #logout_btn = gr.Button("Logout", elem_id="logout-btn")
66
+ # inject auto-reload script
67
+ gr.HTML(
68
+ """
69
+ <script>
70
+ // Reload the page after 1 minutes (300 000 ms)
71
+ setTimeout(() => {
72
+ window.location.reload();
73
+ }, 1000);
74
+ </script>
75
+ """
76
+ )
77
+ gr.ChatInterface(
78
+ chat,
79
+ type="messages",
80
+ editable=True,
81
+ concurrency_limit=200,
82
+ save_history=True,
83
+ )
84
+
85
+
86
+
87
+ demo.queue().launch(auth=AUTHS,share=True, ssr_mode=False)
bedrock_client.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from anthropic import AnthropicBedrock
3
+ from langchain_aws.chat_models import ChatBedrockConverse
4
+ from langchain_aws.llms.bedrock import BedrockLLM
5
+
6
+
7
+
8
+
9
+ # Initialize the streaming Bedrock chat model
10
+ bedrock_llm = ChatBedrockConverse(
11
+ aws_access_key_id =os.environ.get("AWS_ACCESS_KEY_ID"),
12
+ aws_secret_access_key =os.environ.get("AWS_SECRET_ACCESS_KEY"),
13
+ region_name =os.environ.get("AWS_DEFAULT_REGION", "eu-west-1"),
14
+ provider = os.environ.get("PROVIDER", "mistral"),
15
+ model_id =os.environ.get("MODEL_ID", "mistral.mistral-large-2402-v1:0"), # or your preferred Bedrock model
16
+ temperature= 0.7)
17
+
18
+
19
+
20
+
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ gradio>=4.20.0
2
+ boto3>=1.34.0
3
+ botocore
4
+ fastapi
5
+ uvicorn
6
+ aiofiles
7
+ anthropic[bedrock]>=0.50.0
8
+ langchain-aws>=0.2.17
9
+ langchain-community>=0.3.26
static/deval.css ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ── Brand overrides ─────────────────────────────────────────── */
2
+ :root {
3
+ --color-brand-primary: #E7AB12;
4
+ --color-brand-secondary: #0D456C;
5
+ }
6
+
7
+ /* ── Page background ────────────────────────────────────────── */
8
+ body, .gradio-container {
9
+ background-color: #003C66 !important;
10
+ }
11
+
12
+ /* ── Global button look ─────────────────────────────────────── */
13
+ button.gr-button {
14
+ background-color: #003C66 !important;
15
+ color: #E7AB12 !important;
16
+ }
17
+ button.gr-button:hover {
18
+ background-color: #0056b3 !important;
19
+ }
20
+
21
+ /* force the logo container to left‐align its child */
22
+ #logo-primary {
23
+ display: block; /* ensure it’s a block container */
24
+ text-align: left !important;
25
+ }
26
+
27
+ /* still keep your size constraints */
28
+ #logo-primary img {
29
+ max-width: 80%;
30
+ max-height: 90%;
31
+ height: auto;
32
+ object-fit: contain;
33
+ margin: 2 !important;
34
+
35
+ /* nix any auto‐margins that might center it */
36
+ }
37
+
38
+ /* ── Header Markdown styling ───────────────────────────────── */
39
+ #header-text {
40
+ /* overall container */
41
+ font-size: 1.75rem; /* ~23px */
42
+ line-height: 1.6;
43
+ font-weight: bold;
44
+ color: #C1CDDF !important;
45
+ }
46
+
47
+ /* ensure all child text elements inherit that color */
48
+ #header-text,
49
+ #header-text h1,
50
+ #header-text p,
51
+ #header-text strong,
52
+ #header-text b,
53
+ #header-text em {
54
+ color: #C1CDDF !important;
55
+ }
static/logo.png ADDED
utils.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+
3
+ def load_users(path):
4
+ """
5
+ Reads a CSV with header 'users,passwords'
6
+ and returns a list of (user, password) tuples.
7
+ """
8
+ with open(path, newline="", encoding="utf-8") as f:
9
+ reader = csv.DictReader(f)
10
+ return [(row["users"], row["passwords"]) for row in reader]