Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,110 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
9 |
-
messages = [{"role": "system", "content": system_message}]
|
10 |
-
|
11 |
-
for val in history:
|
12 |
-
if val[0]:
|
13 |
-
messages.append({"role": "user", "content": val[0]})
|
14 |
-
if val[1]:
|
15 |
-
messages.append({"role": "assistant", "content": val[1]})
|
16 |
-
|
17 |
-
messages.append({"role": "user", "content": message})
|
18 |
-
|
19 |
-
response = ""
|
20 |
-
|
21 |
-
for message in client.chat_completion(
|
22 |
-
messages,
|
23 |
-
max_tokens=max_tokens,
|
24 |
-
stream=True,
|
25 |
-
temperature=temperature,
|
26 |
-
top_p=top_p,
|
27 |
-
):
|
28 |
-
token = message.choices[0].delta.content
|
29 |
-
response += token
|
30 |
-
yield response
|
31 |
-
|
32 |
-
# Define the Gradio interface
|
33 |
-
demo = gr.Blocks()
|
34 |
-
|
35 |
-
with demo:
|
36 |
-
# Load and display the HTML file
|
37 |
with open("index.html", "r") as file:
|
38 |
-
|
39 |
-
|
40 |
-
gr.HTML(html_content)
|
41 |
-
|
42 |
-
# Create the chat interface
|
43 |
-
gr.ChatInterface(
|
44 |
-
respond,
|
45 |
-
additional_inputs=[
|
46 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
47 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
48 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
49 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
50 |
-
],
|
51 |
-
)
|
52 |
-
|
53 |
-
# Launch the application
|
54 |
-
if __name__ == "__main__":
|
55 |
-
demo.launch()
|
56 |
-
import gradio as gr
|
57 |
-
from huggingface_hub import InferenceClient
|
58 |
-
|
59 |
-
# Initialize the inference client
|
60 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
61 |
-
|
62 |
-
# Define the response function
|
63 |
-
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
64 |
-
messages = [{"role": "system", "content": system_message}]
|
65 |
-
|
66 |
-
for val in history:
|
67 |
-
if val[0]:
|
68 |
-
messages.append({"role": "user", "content": val[0]})
|
69 |
-
if val[1]:
|
70 |
-
messages.append({"role": "assistant", "content": val[1]})
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
for message in client.chat_completion(
|
77 |
-
messages,
|
78 |
-
max_tokens=max_tokens,
|
79 |
-
stream=True,
|
80 |
-
temperature=temperature,
|
81 |
-
top_p=top_p,
|
82 |
-
):
|
83 |
-
token = message.choices[0].delta.content
|
84 |
-
response += token
|
85 |
-
yield response
|
86 |
|
87 |
-
#
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
-
|
91 |
-
# Load and display the HTML file
|
92 |
-
with open("index.html", "r") as file:
|
93 |
-
html_content = file.read()
|
94 |
-
|
95 |
-
gr.HTML(html_content)
|
96 |
-
|
97 |
-
# Create the chat interface
|
98 |
-
gr.ChatInterface(
|
99 |
-
respond,
|
100 |
-
additional_inputs=[
|
101 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
102 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
103 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
104 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
105 |
-
],
|
106 |
-
)
|
107 |
|
108 |
-
# Launch the application
|
109 |
if __name__ == "__main__":
|
110 |
-
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
+
def show_exam_html():
|
4 |
+
with open("exam.html", "r") as file:
|
5 |
+
return file.read()
|
6 |
|
7 |
+
def show_index_html():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
with open("index.html", "r") as file:
|
9 |
+
return file.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
def main():
|
12 |
+
with gr.Blocks() as demo:
|
13 |
+
gr.HTML(show_index_html())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# A hidden HTML component to store and display exam.html content
|
16 |
+
exam_html = gr.HTML(show_exam_html(), visible=False)
|
17 |
+
|
18 |
+
def start_exam():
|
19 |
+
return gr.update(visible=True), gr.update(visible=False)
|
20 |
+
|
21 |
+
# Simulate the navigation event
|
22 |
+
gr.Button("Start Exam").click(start_exam, inputs=[], outputs=[exam_html, gr.HTML(show_index_html())])
|
23 |
|
24 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
|
|
26 |
if __name__ == "__main__":
|
27 |
+
main()
|