J Z commited on
Commit
3ef9356
·
verified ·
1 Parent(s): 97d6b5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -57
app.py CHANGED
@@ -1,62 +1,18 @@
1
- import os
2
- import sys
3
- import subprocess
4
- import time
5
- import signal
6
- import atexit
7
 
8
- # Add the DarwinChatbot scripts directory to the Python path
9
- DARWIN_SCRIPTS_PATH = "/data/DarwinChatbot/scripts"
10
- NICEGUI_PORT = 7860
11
 
12
- # Global process variables
13
- OLLAMA_PROCESS = None
14
- DARWIN_APP_PROCESS = None
15
 
16
- def cleanup():
17
- """Stop all processes on exit"""
18
- if DARWIN_APP_PROCESS:
19
- DARWIN_APP_PROCESS.terminate()
20
-
21
- if OLLAMA_PROCESS:
22
- OLLAMA_PROCESS.terminate()
23
-
24
- # Register cleanup handler
25
- atexit.register(cleanup)
26
- signal.signal(signal.SIGTERM, lambda sig, frame: cleanup())
27
- signal.signal(signal.SIGINT, lambda sig, frame: cleanup())
28
 
29
  if __name__ == "__main__":
30
- # 1. Start Ollama server
31
- print("Starting Ollama server...")
32
- OLLAMA_PROCESS = subprocess.Popen(
33
- ["ollama", "serve"],
34
- stdout=subprocess.DEVNULL,
35
- stderr=subprocess.DEVNULL
36
- )
37
-
38
- # Give Ollama a moment to start
39
- time.sleep(3)
40
-
41
- # 2. Start the Darwin app
42
- print("Starting Darwin Avatar app...")
43
- env = os.environ.copy()
44
- env["NICEGUI_PORT"] = str(NICEGUI_PORT)
45
- env["NICEGUI_HOST"] = "0.0.0.0"
46
-
47
- os.chdir(DARWIN_SCRIPTS_PATH)
48
- DARWIN_APP_PROCESS = subprocess.Popen(
49
- [sys.executable, "app.py"],
50
- env=env,
51
- cwd=DARWIN_SCRIPTS_PATH
52
- )
53
-
54
- print(f"Darwin Avatar is running on port {NICEGUI_PORT}")
55
-
56
- # 3. Keep the main process running
57
- try:
58
- DARWIN_APP_PROCESS.wait()
59
- except KeyboardInterrupt:
60
- pass
61
- finally:
62
- cleanup()
 
1
+ import gradio as gr
2
+ from transformers import pipeline
 
 
 
 
3
 
4
+ pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
 
 
5
 
6
+ def predict(input_img):
7
+ predictions = pipeline(input_img)
8
+ return input_img, {p["label"]: p["score"] for p in predictions}
9
 
10
+ gradio_app = gr.Interface(
11
+ predict,
12
+ inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"),
13
+ outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
14
+ title="Hot Dog? Or Not?",
15
+ )
 
 
 
 
 
 
16
 
17
  if __name__ == "__main__":
18
+ gradio_app.launch()