Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -46,21 +46,30 @@ import gradio as gr
|
|
46 |
from huggingface_hub import InferenceClient
|
47 |
import os
|
48 |
|
49 |
-
|
50 |
-
client = InferenceClient(api_key=token)
|
51 |
|
52 |
-
messages
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
)
|
64 |
|
65 |
-
|
66 |
-
print(chunk.choices[0].delta.content)
|
|
|
46 |
from huggingface_hub import InferenceClient
|
47 |
import os
|
48 |
|
49 |
+
hf_token = os.getenv("HF_TOKEN")
|
|
|
50 |
|
51 |
+
def chat(messages):
|
52 |
+
client = InferenceClient(api_key=hf_token)
|
53 |
+
stream = client.chat.completions.create(
|
54 |
+
model="google/gemma-2-2b-it",
|
55 |
+
messages=messages,
|
56 |
+
#temperature=0.5,
|
57 |
+
#max_tokens=2048,
|
58 |
+
#top_p=0.7,
|
59 |
+
stream=True
|
60 |
+
)
|
61 |
+
story = ""
|
62 |
+
for chunk in stream:
|
63 |
+
story += chunk.choices[0].delta.content
|
64 |
+
return story
|
65 |
|
66 |
+
interface = gr.Interface(
|
67 |
+
fn=chat,
|
68 |
+
inputs="textbox",
|
69 |
+
outputs="textbox",
|
70 |
+
title="Storyteller with Gemma",
|
71 |
+
description="Tell me a story starter and I'll continue it using Gemma!",
|
72 |
+
label="Start your story..."
|
73 |
)
|
74 |
|
75 |
+
interface.launch()
|
|