Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,40 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# Hugging Face token (set in Secrets)
|
| 7 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
-
client = InferenceClient(token=HF_TOKEN, model="openai/gpt-oss-20b")
|
| 9 |
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
history: list = []
|
| 16 |
-
|
| 17 |
-
@app.post("/chat")
|
| 18 |
-
def chat(req: ChatRequest):
|
| 19 |
-
messages = [{"role": "system", "content": "You are a helpful AI assistant."}]
|
| 20 |
-
|
| 21 |
-
for h in req.history:
|
| 22 |
-
messages.append({"role": "user", "content": h[0]})
|
| 23 |
-
messages.append({"role": "assistant", "content": h[1]})
|
| 24 |
-
|
| 25 |
-
messages.append({"role": "user", "content": req.message})
|
| 26 |
|
| 27 |
response = ""
|
| 28 |
for msg in client.chat_completion(
|
| 29 |
messages,
|
| 30 |
-
max_tokens=
|
| 31 |
stream=True,
|
| 32 |
-
temperature=0.7
|
|
|
|
| 33 |
):
|
| 34 |
if msg.choices and msg.choices[0].delta.content:
|
| 35 |
response += msg.choices[0].delta.content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
| 1 |
+
APP.PY sahi UI wala
|
| 2 |
+
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
import os
|
| 5 |
|
|
|
|
| 6 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
| 7 |
|
| 8 |
+
def respond(message, history: list[dict[str, str]]):
|
| 9 |
+
client = InferenceClient(token=HF_TOKEN, model="openai/gpt-oss-20b")
|
| 10 |
|
| 11 |
+
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 12 |
+
messages.extend(history)
|
| 13 |
+
messages.append({"role": "user", "content": message})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
response = ""
|
| 16 |
for msg in client.chat_completion(
|
| 17 |
messages,
|
| 18 |
+
max_tokens=512,
|
| 19 |
stream=True,
|
| 20 |
+
temperature=0.7,
|
| 21 |
+
top_p=0.95
|
| 22 |
):
|
| 23 |
if msg.choices and msg.choices[0].delta.content:
|
| 24 |
response += msg.choices[0].delta.content
|
| 25 |
+
yield response
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# Purple + White/Grey Theme CSS
|
| 29 |
+
custom_css = """
|
| 30 |
+
.gradio-container {
|
| 31 |
+
background: linear-gradient(to bottom right, #7E498B, #f5f5f5);
|
| 32 |
+
font-family: 'Segoe UI', sans-serif;
|
| 33 |
+
}
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
| 37 |
+
gr.ChatInterface(respond, type="messages")
|
| 38 |
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
demo.launch(share=True)
|