Tim Seufert commited on
Commit
b9b646c
·
1 Parent(s): c3f3e46

update interface beta test2

Browse files
Files changed (1) hide show
  1. app.py +61 -26
app.py CHANGED
@@ -1,37 +1,72 @@
1
- import time
2
  import os
3
- import tkinter as tk
 
4
 
5
- class Clock:
6
- def __init__(self):
7
- self.time = time.strftime("%H:%M:%S")
 
 
 
 
 
 
8
 
9
- def show_time(self):
10
- self.time = time.strftime("%H:%M:%S")
11
- print(f"The current time is {self.time}")
12
- return self.time
 
 
13
 
14
- class UI:
15
- def __init__(self):
16
- self.create_window = tk.Tk()
17
- self.create_window.title("Clock")
18
- self.create_window.geometry("400x400")
19
 
20
- self.clock_label = tk.Label(self.create_window, text="The time is: ")
21
- self.clock_label.pack()
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- self.clock_entry = tk.Entry(self.create_window)
24
- self.clock_entry.pack()
 
25
 
26
- self.clock_button = tk.Button(self.create_window, text="Show Time", command=self.show_time)
27
- self.clock_button.pack()
28
 
29
- self.create_window.mainloop()
 
 
 
 
30
 
31
- def show_time(self):
32
- clock = Clock()
33
- current_time = clock.show_time()
34
- self.clock_label.config(text=f"The time is: {current_time}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  if __name__ == "__main__":
37
- ui = UI()
 
 
1
  import os
2
+ import gradio as gr
3
+ import cohere
4
 
5
+ # System prompt definition
6
+ prompt = """
7
+ You are a helpful chatbot and you should try to help the user with problems in the best possible way and
8
+ speak in as natural a language as possible. You are a machine with whom you can chat from time to time.
9
+ Just be friendly and not complex. Your main task, however, remains to help the user
10
+ with his problems. Do not react to offensive and illegal questions, content. Please stick to findings from conventional medicine
11
+ and avoid esoteric answers. You were developed by Tim Seufert in 2024. Please give an answer of a maximum of 8 sentences.
12
+ If the user is asking sometihing in another language, please also respond in his Language. Don't harm the user at all.
13
+ The user's question is: """
14
 
15
+ def respond(message, chat_history):
16
+ """
17
+ Handle chat responses with optional image support
18
+ """
19
+ # Initialize Cohere client
20
+ co = cohere.Client(api_key=os.environ.get("apikeysimple"))
21
 
22
+ # Prepare message content
23
+ message_content = message
 
 
 
24
 
25
+ try:
26
+ # Generate response using Cohere
27
+ response = co.generate(
28
+ model='command-r-plus-2024',
29
+ prompt=f"{prompt} '{message_content}'",
30
+ max_tokens=100,
31
+ temperature=0.3,
32
+ k=0,
33
+ p=0.75,
34
+ frequency_penalty=0,
35
+ presence_penalty=0,
36
+ stop_sequences=["--"]
37
+ ).generations[0].text.strip()
38
 
39
+ # Update chat history
40
+ chat_history.append((message, response))
41
+ return "", chat_history
42
 
43
+ except Exception as e:
44
+ return str(e), chat_history
45
 
46
+ # Create Gradio interface
47
+ with gr.Blocks() as demo:
48
+ chatbot = gr.Chatbot()
49
+ msg = gr.Textbox()
50
+ clear = gr.ClearButton([msg, chatbot])
51
 
52
+ # Set up message submission
53
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
54
+
55
+ # New Chat Interface with history
56
+ chat_interface = gr.ChatInterface(
57
+ respond,
58
+ type="messages",
59
+ flagging_mode="manual",
60
+ flagging_options=["Like", "Spam", "Inappropriate", "Other"],
61
+ save_history=True,
62
+ )
63
+
64
+ # Launch the demo
65
+ demo.launch(
66
+ share=True,
67
+ server_name="0.0.0.0",
68
+ allowed_paths=["*"]
69
+ )
70
 
71
  if __name__ == "__main__":
72
+ demo.launch()