jb3194 commited on
Commit
6b0bb13
·
verified ·
1 Parent(s): 84e5a55

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +48 -69
  2. requirements.txt +17 -0
app.py CHANGED
@@ -1,69 +1,48 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
-
5
- def respond(
6
- message,
7
- history: list[dict[str, str]],
8
- system_message,
9
- max_tokens,
10
- temperature,
11
- top_p,
12
- hf_token: gr.OAuthToken,
13
- ):
14
- """
15
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
16
- """
17
- client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
18
-
19
- messages = [{"role": "system", "content": system_message}]
20
-
21
- messages.extend(history)
22
-
23
- messages.append({"role": "user", "content": message})
24
-
25
- response = ""
26
-
27
- for message in client.chat_completion(
28
- messages,
29
- max_tokens=max_tokens,
30
- stream=True,
31
- temperature=temperature,
32
- top_p=top_p,
33
- ):
34
- choices = message.choices
35
- token = ""
36
- if len(choices) and choices[0].delta.content:
37
- token = choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
-
42
-
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- chatbot = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
- ],
60
- )
61
-
62
- with gr.Blocks() as demo:
63
- with gr.Sidebar():
64
- gr.LoginButton()
65
- chatbot.render()
66
-
67
-
68
- if __name__ == "__main__":
69
- demo.launch()
 
1
+ {\rtf1\ansi\ansicpg1252\cocoartf2868
2
+ \cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fmodern\fcharset0 Courier;}
3
+ {\colortbl;\red255\green255\blue255;\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;
4
+ \red131\green0\blue165;\red15\green112\blue1;\red144\green1\blue18;\red86\green65\blue25;\red0\green0\blue109;
5
+ \red19\green85\blue52;}
6
+ {\*\expandedcolortbl;;\cssrgb\c0\c0\c100000;\cssrgb\c100000\c100000\c100000;\cssrgb\c0\c0\c0;
7
+ \cssrgb\c59216\c13725\c70588;\cssrgb\c0\c50196\c0;\cssrgb\c63922\c8235\c8235;\cssrgb\c41569\c32157\c12941;\cssrgb\c0\c6275\c50196;
8
+ \cssrgb\c6667\c40000\c26667;}
9
+ \paperw11900\paperh16840\margl1440\margr1440\vieww11520\viewh8400\viewkind0
10
+ \deftab720
11
+ \pard\pardeftab720\partightenfactor0
12
+
13
+ \f0\fs28 \cf2 \cb3 \expnd0\expndtw0\kerning0
14
+ \outl0\strokewidth0 \strokec2 %%writefile app.py\cf0 \cb1 \strokec4 \
15
+ \
16
+ \pard\pardeftab720\partightenfactor0
17
+ \cf5 \cb3 \strokec5 import\cf0 \strokec4 gradio \cf5 \strokec5 as\cf0 \strokec4 gr\cb1 \
18
+ \cf5 \cb3 \strokec5 from\cf0 \strokec4 transformers \cf5 \strokec5 import\cf0 \strokec4 pipeline\cb1 \
19
+ \
20
+ \pard\pardeftab720\partightenfactor0
21
+ \cf6 \cb3 \strokec6 # Load the model pipeline\cf0 \cb1 \strokec4 \
22
+ \pard\pardeftab720\partightenfactor0
23
+ \cf0 \cb3 pipe = pipeline(\cf7 \strokec7 "text-generation"\cf0 \strokec4 , model=\cf7 \strokec7 "isaacus/open-australian-legal-llm"\cf0 \strokec4 )\cb1 \
24
+ \
25
+ \pard\pardeftab720\partightenfactor0
26
+ \cf6 \cb3 \strokec6 # Define a function to use the pipeline for text generation\cf0 \cb1 \strokec4 \
27
+ \pard\pardeftab720\partightenfactor0
28
+ \cf2 \cb3 \strokec2 def\cf0 \strokec4 \cf8 \strokec8 generate_text\cf0 \strokec4 (\cf9 \strokec9 prompt\cf0 \strokec4 ):\cb1 \
29
+ \pard\pardeftab720\partightenfactor0
30
+ \cf0 \cb3 outputs = pipe(prompt, max_new_tokens=\cf10 \strokec10 50\cf0 \strokec4 , do_sample=\cf2 \strokec2 True\cf0 \strokec4 , temperature=\cf10 \strokec10 0.7\cf0 \strokec4 )\cb1 \
31
+ \cb3 \cf5 \strokec5 return\cf0 \strokec4 outputs[\cf10 \strokec10 0\cf0 \strokec4 ][\cf7 \strokec7 'generated_text'\cf0 \strokec4 ]\cb1 \
32
+ \
33
+ \pard\pardeftab720\partightenfactor0
34
+ \cf6 \cb3 \strokec6 # Create the Gradio interface\cf0 \cb1 \strokec4 \
35
+ \pard\pardeftab720\partightenfactor0
36
+ \cf0 \cb3 iface = gr.Interface(\cb1 \
37
+ \cb3 fn=generate_text,\cb1 \
38
+ \cb3 inputs=gr.Textbox(lines=\cf10 \strokec10 2\cf0 \strokec4 , placeholder=\cf7 \strokec7 "Enter your prompt here..."\cf0 \strokec4 ),\cb1 \
39
+ \cb3 outputs=\cf7 \strokec7 "text"\cf0 \strokec4 ,\cb1 \
40
+ \cb3 title=\cf7 \strokec7 "Open Australian Legal LLM Chat Interface"\cf0 \strokec4 ,\cb1 \
41
+ \cb3 description=\cf7 \strokec7 "Interact with the Open Australian Legal LLM. Enter a legal question or prompt to get a generated response."\cf0 \cb1 \strokec4 \
42
+ \cb3 )\cb1 \
43
+ \
44
+ \pard\pardeftab720\partightenfactor0
45
+ \cf6 \cb3 \strokec6 # Launch the interface (this will be handled by Hugging Face Spaces when deployed)\cf0 \cb1 \strokec4 \
46
+ \pard\pardeftab720\partightenfactor0
47
+ \cf0 \cb3 iface.launch(share=\cf2 \strokec2 False\cf0 \strokec4 )\cb1 \
48
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {\rtf1\ansi\ansicpg1252\cocoartf2868
2
+ \cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fmodern\fcharset0 Courier;}
3
+ {\colortbl;\red255\green255\blue255;\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;
4
+ }
5
+ {\*\expandedcolortbl;;\cssrgb\c0\c0\c100000;\cssrgb\c100000\c100000\c100000;\cssrgb\c0\c0\c0;
6
+ }
7
+ \paperw11900\paperh16840\margl1440\margr1440\vieww11520\viewh8400\viewkind0
8
+ \deftab720
9
+ \pard\pardeftab720\partightenfactor0
10
+
11
+ \f0\fs28 \cf2 \cb3 \expnd0\expndtw0\kerning0
12
+ \outl0\strokewidth0 \strokec2 %%writefile requirements.txt\cf0 \cb1 \strokec4 \
13
+ \
14
+ \pard\pardeftab720\partightenfactor0
15
+ \cf0 \cb3 gradio\cb1 \
16
+ \cb3 transformers\cb1 \
17
+ }