richardkimsm89 commited on
Commit
dc3a5c3
·
verified ·
1 Parent(s): 3f80280

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -14
app.py CHANGED
@@ -46,21 +46,30 @@ import gradio as gr
46
  from huggingface_hub import InferenceClient
47
  import os
48
 
49
- token = os.getenv("HF_TOKEN")
50
- client = InferenceClient(api_key=token)
51
 
52
- messages = [
53
- { "role": "user", "content": "Tell me a story" }
54
- ]
 
 
 
 
 
 
 
 
 
 
 
55
 
56
- stream = client.chat.completions.create(
57
- model="google/gemma-2-2b-it",
58
- messages=messages,
59
- temperature=0.5,
60
- max_tokens=2048,
61
- top_p=0.7,
62
- stream=True
63
  )
64
 
65
- for chunk in stream:
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()