DataBob commited on
Commit
2551a3c
1 Parent(s): 529d3fe

gradio app

Browse files
Files changed (1) hide show
  1. app.py +86 -4
app.py CHANGED
@@ -1,7 +1,89 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
 
4
+ from query_data import query_data
5
+ from create_database import split_text
6
+ import os
7
+ import shutil
8
 
9
+
10
+ import logging
11
+
12
+ logging.basicConfig(filename='myapp.log',format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
13
+ logger = logging.getLogger(__name__)
14
+
15
+ """
16
+ 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
17
+ """
18
+
19
+
20
+ CHROMA_PATH = "chroma"
21
+ DATA_PATH = "./data"
22
+
23
+
24
+ accesstoken = os.environ['HF_TOKEN']
25
+ checkpoint = "HuggingFaceH4/zephyr-7b-beta"
26
+ client = InferenceClient(checkpoint,token = accesstoken)
27
+
28
+ def upload_file(file):
29
+ if not os.path.exists(DATA_PATH):
30
+ os.mkdir(DATA_PATH)
31
+
32
+ shutil.copy(file,DATA_PATH)
33
+ gr.Info("File uploading")
34
+
35
+
36
+ logger.info("### Inference client: "+checkpoint)
37
+
38
+
39
+
40
+ def respond(
41
+ message,
42
+ history: list[tuple[str, str]],
43
+ system_message,
44
+ max_tokens,
45
+ temperature,
46
+ top_p,
47
+ ):
48
+ messages = [{"role": "system", "content": system_message}]
49
+
50
+ for val in history:
51
+ if val[0]:
52
+ messages.append({"role": "user", "content": val[0]})
53
+ if val[1]:
54
+ messages.append({"role": "assistant", "content": val[1]})
55
+
56
+ messages.append({"role": "user", "content": message})
57
+
58
+ logger.info(messages)
59
+ response = query_data(message)
60
+ yield response
61
+
62
+
63
+ """
64
+ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
65
+ """
66
+ with gr.Blocks() as demo:
67
+
68
+ upload_button = gr.UploadButton("Click the button to upload")
69
+ upload_button.upload(upload_file,upload_button)
70
+
71
+ gr.ChatInterface(
72
+ respond,
73
+ additional_inputs=[
74
+ gr.Textbox(value="You are a friendly Chatbot that helps searching knowledge into scientific articles.", label="System message"),
75
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
76
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
77
+ gr.Slider(
78
+ minimum=0.1,
79
+ maximum=1.0,
80
+ value=0.95,
81
+ step=0.05,
82
+ label="Top-p (nucleus sampling)",
83
+ )
84
+ ],
85
+ )
86
+
87
+
88
+ if __name__ == "__main__":
89
+ demo.launch()