Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,72 +1,54 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
"""
|
| 5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
-
"""
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
messages = [{"role": "system", "content": system_message}]
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
response = ""
|
| 29 |
-
|
| 30 |
for message in client.chat_completion(
|
| 31 |
messages,
|
| 32 |
-
max_tokens=
|
| 33 |
stream=True,
|
| 34 |
-
temperature=
|
| 35 |
-
top_p=
|
| 36 |
):
|
| 37 |
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
response += token
|
| 40 |
yield response
|
| 41 |
|
| 42 |
-
|
| 43 |
-
"""
|
| 44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
-
"""
|
| 46 |
demo = gr.ChatInterface(
|
| 47 |
respond,
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
value=0.95,
|
| 56 |
-
step=0.05,
|
| 57 |
-
label="Top-p (nucleus sampling)",
|
| 58 |
-
),
|
| 59 |
],
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
-
###updated 2.27.2025 to go public###
|
| 63 |
-
# ✅ Define the Gradio interface BEFORE launching
|
| 64 |
-
iface = gr.Interface(
|
| 65 |
-
fn=chatbot_response,
|
| 66 |
-
inputs="text",
|
| 67 |
-
outputs="text",
|
| 68 |
-
title="CYOA Adventure Bot",
|
| 69 |
-
description="Type your choices and shape the adventure!")
|
| 70 |
-
|
| 71 |
if __name__ == "__main__":
|
| 72 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 5 |
|
| 6 |
+
def respond(message, history):
|
| 7 |
+
system_message = """You are an interactive storyteller creating an immersive choose-your-own-adventure story.
|
| 8 |
+
For each response:
|
| 9 |
+
1. Provide vivid descriptions of the scene and characters
|
| 10 |
+
2. Include meaningful dialogue or internal monologue
|
| 11 |
+
3. End with 3 different possible actions or decisions, phrased as complete sentences
|
| 12 |
+
Example endings:
|
| 13 |
+
- You could try climbing the ancient tree to get a better view
|
| 14 |
+
- Perhaps investigating the strange sound from the cave would reveal something
|
| 15 |
+
- Maybe approaching the mysterious stranger to ask for directions is wise
|
| 16 |
+
Keep responses engaging but concise."""
|
| 17 |
+
|
| 18 |
messages = [{"role": "system", "content": system_message}]
|
| 19 |
+
|
| 20 |
+
# Add history and current message
|
| 21 |
+
for user_msg, bot_msg in history:
|
| 22 |
+
messages.append({"role": "user", "content": user_msg})
|
| 23 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
| 24 |
+
|
|
|
|
| 25 |
messages.append({"role": "user", "content": message})
|
| 26 |
+
|
| 27 |
response = ""
|
|
|
|
| 28 |
for message in client.chat_completion(
|
| 29 |
messages,
|
| 30 |
+
max_tokens=512,
|
| 31 |
stream=True,
|
| 32 |
+
temperature=0.7,
|
| 33 |
+
top_p=0.95,
|
| 34 |
):
|
| 35 |
token = message.choices[0].delta.content
|
|
|
|
| 36 |
response += token
|
| 37 |
yield response
|
| 38 |
|
| 39 |
+
# Create Gradio interface
|
|
|
|
|
|
|
|
|
|
| 40 |
demo = gr.ChatInterface(
|
| 41 |
respond,
|
| 42 |
+
title="Interactive Story Adventure",
|
| 43 |
+
description="Describe what you want to do next in the story using natural language...",
|
| 44 |
+
examples=[
|
| 45 |
+
"Begin my adventure",
|
| 46 |
+
"I want to explore the mysterious cave",
|
| 47 |
+
"Let's try talking to the merchant",
|
| 48 |
+
"I decide to climb the tower"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
],
|
| 50 |
+
theme=gr.themes.Soft()
|
| 51 |
)
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
if __name__ == "__main__":
|
| 54 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|