Poonawala commited on
Commit
cf6c208
·
verified ·
1 Parent(s): ca99935

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -118
app.py DELETED
@@ -1,118 +0,0 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- # Define the InferenceClient for different models
5
- client_chatgpt = InferenceClient("openai/gpt-3.5-turbo") # Example for ChatGPT model
6
- client_llama = InferenceClient("meta-llama/Llama-3.2-3B-Instruct") # Llama model
7
- client_claude = InferenceClient("anthropic/claude-1") # Claude model (adjust with correct model path)
8
-
9
- def respond(
10
- message,
11
- history: list[tuple[str, str]],
12
- system_message,
13
- max_tokens,
14
- temperature,
15
- top_p,
16
- ):
17
- messages = [{"role": "system", "content": system_message}]
18
-
19
- for val in history:
20
- if val[0]:
21
- messages.append({"role": "user", "content": val[0]})
22
- if val[1]:
23
- messages.append({"role": "assistant", "content": val[1]})
24
-
25
- messages.append({"role": "user", "content": message})
26
-
27
- response = ""
28
-
29
- for message in client_llama.chat_completion( # Defaulting to Llama, update dynamically later
30
- messages,
31
- max_tokens=max_tokens,
32
- stream=True,
33
- temperature=temperature,
34
- top_p=top_p,
35
- ):
36
- token = message.choices[0].delta.content
37
-
38
- response += token
39
- yield response
40
-
41
- # Function to handle button clicks for different models
42
- def on_button_click(model_name, message, history, system_message, max_tokens, temperature, top_p):
43
- # Choose the client based on the selected model
44
- if model_name == "Chatgpt":
45
- client = client_chatgpt
46
- elif model_name == "Llama":
47
- client = client_llama
48
- elif model_name == "Claude":
49
- client = client_claude
50
- else:
51
- return "Unknown model selected."
52
-
53
- messages = [{"role": "system", "content": system_message}]
54
-
55
- for val in history:
56
- if val[0]:
57
- messages.append({"role": "user", "content": val[0]})
58
- if val[1]:
59
- messages.append({"role": "assistant", "content": val[1]})
60
-
61
- messages.append({"role": "user", "content": message})
62
-
63
- response = ""
64
-
65
- # Call the selected model for completion
66
- for message in client.chat_completion(
67
- messages,
68
- max_tokens=max_tokens,
69
- stream=True,
70
- temperature=temperature,
71
- top_p=top_p,
72
- ):
73
- token = message.choices[0].delta.content
74
- response += token
75
- yield response
76
-
77
- # CSS for styling the interface
78
- css = """
79
- body {
80
- background-color: #06688E; /* Dark background */
81
- color: white; /* Text color for better visibility */
82
- }
83
- .gr-button {
84
- background-color: #42B3CE !important; /* White button color */
85
- color: black !important; /* Black text for contrast */
86
- border: none !important;
87
- padding: 8px 16px !important;
88
- border-radius: 5px !important;
89
- }
90
- .gr-button:hover {
91
- background-color: #e0e0e0 !important; /* Slightly lighter button on hover */
92
- }
93
- .gr-slider-container {
94
- color: white !important; /* Slider labels in white */
95
- }
96
- """
97
-
98
- # Interface using Blocks context
99
- with gr.Blocks() as demo:
100
- # Add all your components here, including buttons
101
- system_message = gr.Textbox(value="You are a virtual health assistant...", label="System message", visible=False)
102
- message_input = gr.Textbox(label="User message")
103
- history = gr.State([]) # Keep the history of interactions
104
- max_tokens_slider = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
105
- temperature_slider = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
106
- top_p_slider = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
107
-
108
- # Buttons to select the model
109
- gr.Button("Chatgpt").click(on_button_click, inputs=[message_input, history, system_message, max_tokens_slider, temperature_slider, top_p_slider], outputs="text")
110
- gr.Button("Llama").click(on_button_click, inputs=[message_input, history, system_message, max_tokens_slider, temperature_slider, top_p_slider], outputs="text")
111
- gr.Button("Claude").click(on_button_click, inputs=[message_input, history, system_message, max_tokens_slider, temperature_slider, top_p_slider], outputs="text")
112
-
113
- # Optional: customize your layout with CSS if needed
114
- demo.css = css
115
-
116
- # Launch the app
117
- if __name__ == "__main__":
118
- demo.launch(share=True)