TeePoat commited on
Commit
d4f05e7
·
verified ·
1 Parent(s): 65acc50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -77
app.py CHANGED
@@ -1,83 +1,14 @@
1
- import spaces
2
  import gradio as gr
3
- from fastapi import FastAPI
4
- from huggingface_hub import InferenceClient
5
 
 
 
6
 
7
- app = FastAPI()
8
-
9
-
10
- @app.get("/")
11
- def read_main():
12
- return {"message": "This is your main app"}
13
-
14
- @spaces.GPU
15
- def respond(
16
- message,
17
- history: list[dict[str, str]],
18
- system_message,
19
- max_tokens,
20
- temperature,
21
- top_p,
22
- hf_token: gr.OAuthToken,
23
- ):
24
- """
25
- 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
26
- """
27
- client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
28
-
29
- messages = [{"role": "system", "content": system_message}]
30
-
31
- messages.extend(history)
32
-
33
- messages.append({"role": "user", "content": message})
34
-
35
- response = ""
36
-
37
- for message in client.chat_completion(
38
- messages,
39
- max_tokens=max_tokens,
40
- stream=True,
41
- temperature=temperature,
42
- top_p=top_p,
43
- ):
44
- choices = message.choices
45
- token = ""
46
- if len(choices) and choices[0].delta.content:
47
- token = choices[0].delta.content
48
-
49
- response += token
50
- yield response
51
-
52
-
53
- """
54
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
55
- """
56
- chatbot = gr.ChatInterface(
57
- respond,
58
- additional_inputs=[
59
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
60
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
61
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
62
- gr.Slider(
63
- minimum=0.1,
64
- maximum=1.0,
65
- value=0.95,
66
- step=0.05,
67
- label="Top-p (nucleus sampling)",
68
- ),
69
- ],
70
  )
71
 
72
- with gr.Blocks() as demo:
73
- with gr.Sidebar():
74
- gr.LoginButton()
75
- chatbot.render()
76
-
77
-
78
  if __name__ == "__main__":
79
- import uvicorn
80
- uvicorn.run(app, host="0.0.0.0", port=8000)
81
-
82
- # if __name__ == "__main__":
83
- # demo.launch()
 
 
1
  import gradio as gr
 
 
2
 
3
+ def greet(name, intensity):
4
+ return "Hello, " + name + "!" * int(intensity)
5
 
6
+ demo = gr.Interface(
7
+ fn=greet,
8
+ inputs=["text", "slider"],
9
+ outputs=["text"],
10
+ api_name="predict"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  )
12
 
 
 
 
 
 
 
13
  if __name__ == "__main__":
14
+ demo.launch()