Tijmen2 commited on
Commit
dd699aa
·
verified ·
1 Parent(s): 39101eb

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -78
app.py DELETED
@@ -1,78 +0,0 @@
1
- import os
2
- import gradio as gr
3
- from huggingface_hub import InferenceClient
4
- import requests
5
-
6
- # Define the file path and URL
7
- model_filename = "AstroSage-8B-Q8.0.gguf"
8
- model_url = "https://huggingface.co/AstroMLab/AstroSage-8B-GGUF/resolve/main/AstroSage-8B-Q8.0.gguf"
9
-
10
- # Check if the model file exists locally; if not, download it
11
- if not os.path.exists(model_filename):
12
- print(f"{model_filename} not found. Downloading...")
13
- response = requests.get(model_url, stream=True)
14
- response.raise_for_status() # Check for any download errors
15
- with open(model_filename, "wb") as f:
16
- for chunk in response.iter_content(chunk_size=8192):
17
- f.write(chunk)
18
- print(f"Downloaded {model_filename} successfully.")
19
-
20
- # Initialize the InferenceClient with the local file path
21
- client = InferenceClient(model_filename)
22
-
23
-
24
- def respond(
25
- message,
26
- history: list[tuple[str, str]],
27
- system_message,
28
- max_tokens,
29
- temperature,
30
- top_p,
31
- ):
32
- messages = [{"role": "system", "content": system_message}]
33
-
34
- for val in history:
35
- if val[0]:
36
- messages.append({"role": "user", "content": val[0]})
37
- if val[1]:
38
- messages.append({"role": "assistant", "content": val[1]})
39
-
40
- messages.append({"role": "user", "content": message})
41
-
42
- response = ""
43
-
44
- for message in client.chat_completion(
45
- messages,
46
- max_tokens=max_tokens,
47
- stream=True,
48
- temperature=temperature,
49
- top_p=top_p,
50
- ):
51
- token = message.choices[0].delta.content
52
-
53
- response += token
54
- yield response
55
-
56
-
57
- # Gradio Chat Interface
58
- demo = gr.ChatInterface(
59
- respond,
60
- additional_inputs=[
61
- gr.Textbox(
62
- value="Assume the role of AstroSage, a helpful chatbot designed to answer user queries about astronomy, astrophysics, and cosmology.",
63
- label="System message",
64
- ),
65
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
66
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
67
- gr.Slider(
68
- minimum=0.1,
69
- maximum=1.0,
70
- value=0.95,
71
- step=0.05,
72
- label="Top-p (nucleus sampling)",
73
- ),
74
- ],
75
- )
76
-
77
- if __name__ == "__main__":
78
- demo.launch()