tbelvin5969 commited on
Commit
3bdd3d8
·
verified ·
1 Parent(s): 95b023e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -81
app.py CHANGED
@@ -1,28 +1,8 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- from huggingface_hub import snapshot_download
5
- import torch
6
-
7
- # Download the model snapshot
8
- model_dir = snapshot_download("Genius-Society/insecta")
9
-
10
- # Load your model here using torch or the appropriate framework
11
- # Example placeholder (replace with actual model loading code)
12
- # model = torch.load(os.path.join(model_dir, "model_file.pt"))
13
-
14
- """
15
- 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
16
- """
17
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
18
-
19
  import gradio as gr
20
  from PIL import Image
21
 
22
  def detect_insect(image):
23
- # Preprocess image and run inference with your loaded model
24
- # Placeholder: replace with actual model inference code
25
- # result = model.predict(image)
26
  result = "Detected insect: Example species"
27
  return result
28
 
@@ -33,63 +13,4 @@ iface = gr.Interface(
33
  title="Insect Detector"
34
  )
35
 
36
- if __name__ == "__main__":
37
- iface.launch()
38
-
39
-
40
-
41
- def respond(
42
- message,
43
- history: list[tuple[str, str]],
44
- system_message,
45
- max_tokens,
46
- temperature,
47
- top_p,
48
- ):
49
- messages = [{"role": "system", "content": system_message}]
50
-
51
- for val in history:
52
- if val[0]:
53
- messages.append({"role": "user", "content": val[0]})
54
- if val[1]:
55
- messages.append({"role": "assistant", "content": val[1]})
56
-
57
- messages.append({"role": "user", "content": message})
58
-
59
- response = ""
60
-
61
- for message in client.chat_completion(
62
- messages,
63
- max_tokens=max_tokens,
64
- stream=True,
65
- temperature=temperature,
66
- top_p=top_p,
67
- ):
68
- token = message.choices[0].delta.content
69
-
70
- response += token
71
- yield response
72
-
73
-
74
- """
75
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
76
- """
77
- demo = gr.ChatInterface(
78
- respond,
79
- additional_inputs=[
80
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
81
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
82
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
83
- gr.Slider(
84
- minimum=0.1,
85
- maximum=1.0,
86
- value=0.95,
87
- step=0.05,
88
- label="Top-p (nucleus sampling)",
89
- ),
90
- ],
91
- )
92
-
93
-
94
- if __name__ == "__main__":
95
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from PIL import Image
3
 
4
  def detect_insect(image):
5
+ # Your actual model inference code goes here
 
 
6
  result = "Detected insect: Example species"
7
  return result
8
 
 
13
  title="Insect Detector"
14
  )
15
 
16
+ iface.launch() # Do not put this inside "if __name__ == '__main__'"