Files changed (1) hide show
  1. app.py +4 -15
app.py CHANGED
@@ -13,7 +13,7 @@ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
13
  class Request(BaseModel):
14
  message: str
15
  history: list[tuple[str, str]] = []
16
- system_message: str = "You are Sebari-chan, a friendly and helpful AI assistant."
17
  max_tokens: int = 512
18
  temperature: float = 0.7
19
  top_p: float = 0.95
@@ -30,7 +30,7 @@ def chat(req: Request):
30
 
31
  messages.append({"role": "user", "content": req.message})
32
 
33
- # Generate response
34
  response_text = client.generate(
35
  prompt=req.message,
36
  max_new_tokens=req.max_tokens,
@@ -40,19 +40,8 @@ def chat(req: Request):
40
 
41
  return {"response": response_text}
42
 
43
- # Gradio Chat UI for Sebari-chan
44
- def sebari_chat(user_input, history=[]):
45
- req = Request(message=user_input, history=history)
46
- response = chat(req)
47
- return response["response"]
48
-
49
- # Create Gradio Chat UI
50
- with gr.Blocks() as sebari_ui:
51
- gr.Markdown("# 🟦 Sebari-chan Chat") # Title
52
- chatbot = gr.ChatInterface(fn=sebari_chat, title="Sebari-chan")
53
-
54
- # Mount Gradio UI to FastAPI
55
- app = gr.mount_gradio_app(app, sebari_ui, path="/")
56
 
57
  if __name__ == "__main__":
58
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
13
  class Request(BaseModel):
14
  message: str
15
  history: list[tuple[str, str]] = []
16
+ system_message: str = "You are a friendly chatbot."
17
  max_tokens: int = 512
18
  temperature: float = 0.7
19
  top_p: float = 0.95
 
30
 
31
  messages.append({"role": "user", "content": req.message})
32
 
33
+ # 🔹 Change from `chat_completion()` to `generate()`
34
  response_text = client.generate(
35
  prompt=req.message,
36
  max_new_tokens=req.max_tokens,
 
40
 
41
  return {"response": response_text}
42
 
43
+ # Mount FastAPI app to Gradio
44
+ app.mount("/", app)
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  if __name__ == "__main__":
47
  uvicorn.run(app, host="0.0.0.0", port=7860)