Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,88 +0,0 @@
|
|
| 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 |
-
|
| 8 |
-
# Load the inference client
|
| 9 |
-
client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
|
| 10 |
-
|
| 11 |
-
# Function to handle the chat interaction
|
| 12 |
-
def respond(
|
| 13 |
-
message,
|
| 14 |
-
history: list[tuple[str, str]],
|
| 15 |
-
system_message,
|
| 16 |
-
max_tokens,
|
| 17 |
-
temperature,
|
| 18 |
-
top_p,
|
| 19 |
-
):
|
| 20 |
-
# Prepare the system message and chat history
|
| 21 |
-
messages = [{"role": "system", "content": system_message}]
|
| 22 |
-
|
| 23 |
-
for val in history:
|
| 24 |
-
if val[0]: # User's message
|
| 25 |
-
messages.append({"role": "user", "content": val[0]})
|
| 26 |
-
if val[1]: # Assistant's response
|
| 27 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 28 |
-
|
| 29 |
-
# Add the new user message
|
| 30 |
-
messages.append({"role": "user", "content": message})
|
| 31 |
-
|
| 32 |
-
response = ""
|
| 33 |
-
|
| 34 |
-
# Use `stream=True` to receive token-by-token responses
|
| 35 |
-
for message in client.chat_completion(
|
| 36 |
-
messages=messages,
|
| 37 |
-
max_tokens=max_tokens,
|
| 38 |
-
stream=True,
|
| 39 |
-
temperature=temperature,
|
| 40 |
-
top_p=top_p,
|
| 41 |
-
use_cache=True, # Enable caching for efficiency
|
| 42 |
-
):
|
| 43 |
-
# Append the content of the generated token
|
| 44 |
-
token = message.choices[0].delta.content
|
| 45 |
-
response += token
|
| 46 |
-
yield response # Stream the response incrementally to the interface
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
"""
|
| 50 |
-
Customize the ChatInterface using Gradio. For details, check Gradio's documentation:
|
| 51 |
-
https://www.gradio.app/docs/chatinterface
|
| 52 |
-
"""
|
| 53 |
-
demo = gr.ChatInterface(
|
| 54 |
-
fn=respond, # Function to handle the chat
|
| 55 |
-
additional_inputs=[
|
| 56 |
-
gr.Textbox(
|
| 57 |
-
value="You are a friendly and helpful assistant.",
|
| 58 |
-
label="System message",
|
| 59 |
-
), # Default system message
|
| 60 |
-
gr.Slider(
|
| 61 |
-
minimum=1,
|
| 62 |
-
maximum=2048,
|
| 63 |
-
value=512,
|
| 64 |
-
step=1,
|
| 65 |
-
label="Max new tokens",
|
| 66 |
-
), # Slider to control max token limit
|
| 67 |
-
gr.Slider(
|
| 68 |
-
minimum=0.1,
|
| 69 |
-
maximum=2.0,
|
| 70 |
-
value=0.7,
|
| 71 |
-
step=0.1,
|
| 72 |
-
label="Temperature",
|
| 73 |
-
), # Slider to adjust temperature
|
| 74 |
-
gr.Slider(
|
| 75 |
-
minimum=0.1,
|
| 76 |
-
maximum=1.0,
|
| 77 |
-
value=0.9,
|
| 78 |
-
step=0.05,
|
| 79 |
-
label="Top-p (nucleus sampling)",
|
| 80 |
-
), # Slider to adjust top-p
|
| 81 |
-
],
|
| 82 |
-
title="AI Chatbot Interface",
|
| 83 |
-
description="Interact with the AI model using this chat interface. Adjust generation parameters for better control.",
|
| 84 |
-
)
|
| 85 |
-
|
| 86 |
-
# Launch the Gradio interface
|
| 87 |
-
if __name__ == "__main__":
|
| 88 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|