Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
client = InferenceClient("unsloth/llama-3.2-3b-instruct-bnb-4bit", timeout=
|
| 5 |
-
def respond(message, max_tokens, temperature, top_p):
|
| 6 |
-
response = ""
|
| 7 |
-
|
| 8 |
-
# Use the text generation API
|
| 9 |
-
for message in client.text_generation(
|
| 10 |
-
message,
|
| 11 |
-
max_new_tokens=max_tokens,
|
| 12 |
-
temperature=temperature,
|
| 13 |
-
top_p=top_p,
|
| 14 |
-
stream=True
|
| 15 |
-
):
|
| 16 |
-
token = message["generated_text"]
|
| 17 |
-
response += token
|
| 18 |
-
yield response
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
# Create Gradio Interface
|
| 22 |
demo = gr.Interface(
|
| 23 |
fn=respond,
|
| 24 |
inputs=[
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
client = InferenceClient("unsloth/llama-3.2-3b-instruct-bnb-4bit", timeout=120)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def respond(message, max_tokens, temperature, top_p):
|
| 7 |
+
try:
|
| 8 |
+
result = client.text_generation(
|
| 9 |
+
message,
|
| 10 |
+
max_new_tokens=max_tokens,
|
| 11 |
+
temperature=temperature,
|
| 12 |
+
top_p=top_p
|
| 13 |
+
)
|
| 14 |
+
return result["generated_text"]
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return f"Error: {e}"
|
| 17 |
|
|
|
|
| 18 |
demo = gr.Interface(
|
| 19 |
fn=respond,
|
| 20 |
inputs=[
|