Poonawala commited on
Commit
31bf4a0
·
verified ·
1 Parent(s): 9c39175

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -86
app.py DELETED
@@ -1,86 +0,0 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- client = InferenceClient("meta-llama/Llama-3.2-3B-Instruct")
5
-
6
- def respond(
7
- model_name,
8
- message,
9
- history: list[tuple[str, str]],
10
- system_message,
11
- ):
12
- messages = [{"role": "system", "content": system_message}]
13
-
14
- for val in history:
15
- if val[0]:
16
- messages.append({"role": "user", "content": val[0]})
17
- if val[1]:
18
- messages.append({"role": "assistant", "content": val[1]})
19
-
20
- messages.append({"role": "user", "content": message})
21
-
22
- response = ""
23
-
24
- if model_name == "Llama":
25
- for message in client.chat_completion(
26
- messages,
27
- max_tokens=512,
28
- stream=True,
29
- temperature=0.7,
30
- top_p=0.95,
31
- ):
32
- token = message.choices[0].delta.content
33
- response += token
34
- elif model_name == "Chatgpt":
35
- response = "ChatGPT functionality is not yet implemented."
36
- elif model_name == "Claude":
37
- response = "Claude functionality is not yet implemented."
38
- else:
39
- response = "Model not recognized."
40
-
41
- return response
42
-
43
-
44
- # CSS for styling the interface
45
- css = """
46
- body {
47
- background-color: #06688E; /* Dark background */
48
- color: white; /* Text color for better visibility */
49
- }
50
- .gr-button {
51
- background-color: #42B3CE !important; /* White button color */
52
- color: black !important; /* Black text for contrast */
53
- border: none !important;
54
- padding: 8px 16px !important;
55
- border-radius: 5px !important;
56
- }
57
- .gr-button:hover {
58
- background-color: #e0e0e0 !important; /* Slightly lighter button on hover */
59
- }
60
- """
61
-
62
- # Define the button click handler to hide the dropdown
63
- def on_button_click(model_name, message, history, system_message, dropdown_state):
64
- # Close the dropdown by setting the state to False
65
- return respond(model_name, message, history, system_message), gr.update(visible=False)
66
-
67
- # Define the Gradio interface with buttons and model selection
68
- demo = gr.Interface(
69
- fn=on_button_click,
70
- inputs=[
71
- gr.Textbox(value="Hello!", label="User Message"),
72
- gr.Textbox(value="You are a virtual health assistant. Your primary goal is to assist with health-related queries.", label="System Message", visible=False),
73
- gr.Button("Chatgpt"),
74
- gr.Button("Llama"),
75
- gr.Button("Claude"),
76
- gr.State(value=False), # Add state to track visibility of the dropdown
77
- ],
78
- outputs=[
79
- "text", # For the model's response
80
- gr.State(value=True), # This should be the state output, which tracks visibility
81
- ],
82
- css=css, # Pass the custom CSS here
83
- )
84
-
85
- if __name__ == "__main__":
86
- demo.launch(share=True)