Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -56,65 +56,4 @@ app = gr.TabbedInterface(
|
|
56 |
).launch()
|
57 |
|
58 |
#if __name__ == "__main__":
|
59 |
-
# app.launch()
|
60 |
-
|
61 |
-
"""
|
62 |
-
# Inference
|
63 |
-
|
64 |
-
import gradio as gr
|
65 |
-
from huggingface_hub import InferenceClient
|
66 |
-
|
67 |
-
model = "google/gemma-2-27b-it"
|
68 |
-
#model = "google/gemma-2-9b-it"
|
69 |
-
#model = "google/gemma-2-2b-it"
|
70 |
-
client = InferenceClient(model)
|
71 |
-
|
72 |
-
def fn(
|
73 |
-
message,
|
74 |
-
history: list[tuple[str, str]],
|
75 |
-
#system_message,
|
76 |
-
max_tokens,
|
77 |
-
temperature,
|
78 |
-
top_p,
|
79 |
-
):
|
80 |
-
#messages = [{"role": "system", "content": system_message}]
|
81 |
-
messages = []
|
82 |
-
|
83 |
-
for val in history:
|
84 |
-
if val[0]:
|
85 |
-
messages.append({"role": "user", "content": val[0]})
|
86 |
-
if val[1]:
|
87 |
-
#messages.append({"role": "assistant", "content": val[1]})
|
88 |
-
messages.append({"role": "bot", "content": val[1]})
|
89 |
-
|
90 |
-
messages.append({"role": "user", "content": message})
|
91 |
-
|
92 |
-
response = ""
|
93 |
-
|
94 |
-
for message in client.chat_completion(
|
95 |
-
messages,
|
96 |
-
max_tokens = max_tokens,
|
97 |
-
temperature = temperature,
|
98 |
-
top_p = top_p,
|
99 |
-
stream = True,
|
100 |
-
):
|
101 |
-
token = message.choices[0].delta.content
|
102 |
-
|
103 |
-
response += token
|
104 |
-
yield response
|
105 |
-
|
106 |
-
app = gr.ChatInterface(
|
107 |
-
fn = fn,
|
108 |
-
#type = "messages",
|
109 |
-
additional_inputs = [
|
110 |
-
#gr.Textbox(value="You are a helpful assistant.", label="System Message"),
|
111 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max Tokens"),
|
112 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
113 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-P"),
|
114 |
-
],
|
115 |
-
title = "Google Gemma",
|
116 |
-
description = model,
|
117 |
-
)
|
118 |
-
|
119 |
-
if __name__ == "__main__":
|
120 |
-
app.launch()
|
|
|
56 |
).launch()
|
57 |
|
58 |
#if __name__ == "__main__":
|
59 |
+
# app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|