Sarath0x8f commited on
Commit
4474f90
·
verified ·
1 Parent(s): 92a01f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -17
app.py CHANGED
@@ -1,12 +1,13 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- """
5
- 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
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
9
 
 
10
  def respond(
11
  message,
12
  history: list[tuple[str, str]],
@@ -15,18 +16,27 @@ def respond(
15
  temperature,
16
  top_p,
17
  ):
18
- messages = [{"role": "system", "content": system_message}]
 
 
 
 
 
 
19
 
 
20
  for val in history:
21
  if val[0]:
22
  messages.append({"role": "user", "content": val[0]})
23
  if val[1]:
24
  messages.append({"role": "assistant", "content": val[1]})
25
 
 
26
  messages.append({"role": "user", "content": message})
27
 
28
  response = ""
29
 
 
30
  for message in client.chat_completion(
31
  messages,
32
  max_tokens=max_tokens,
@@ -35,30 +45,85 @@ def respond(
35
  top_p=top_p,
36
  ):
37
  token = message.choices[0].delta.content
38
-
39
  response += token
40
  yield response
41
 
42
 
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
  demo = gr.ChatInterface(
47
  respond,
48
  additional_inputs=[
49
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
  ],
60
  )
61
 
62
-
63
  if __name__ == "__main__":
64
  demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ data = '''
5
+ SARATH CHANDRA BANDREDDI **Professional Summary** Intern-level Python Developer skilled in AI, Django, and web development. Proficient in Python and AI, dedicated to continuous learning. Keen to contribute to software solutions and collaborate in a team environment. **Education** B.Tech in Computer Science (AI & ML), Vasireddy Venkatadri Institute of Technology, India (2021–2025), GPA: 8.60 **Tech Stack** - **Languages**: Python, Java, JavaScript, C, R, Shell - **Frontend**: HTML, CSS, Jinja - **Libraries**: TensorFlow, Keras, LlamaIndex, OpenCV, Sklearn, Numpy, Pandas, Django - **Platforms**: Kaggle, Google-Colabs, Git, GitHub, AWS, Figma - **Databases**: SQL, Oracle, MySQL **Projects** - **Face Recognition** (VGGFace | TensorFlow, Keras, OpenCV, Django) Developed a face recognition app achieving 97.86% accuracy on a 31-class dataset. Launched through Django on an online server. - **SCRAM** (Gemini-pro LLM, Google API, TensorFlow, Django) Built a Django-based college resource management system with LLM chatbot, face recognition, and 2-FS authentication. - **Document & Data Query AI Agent** (Llama3, Ollama, LlamaIndex) Created an AI agent for document-based Q&A and CSV visualization, integrating NLP and data retrieval. **Certifications** Python: Kaggle, SoloLearn, HackerRank, GUVI ML: Coursera, Kaggle, Microsoft, IBM Deep Learning: NPTEL, Kaggle, IBM Django: Microsoft AWS: AWS Academy Cloud Foundations, Cloud Architecting NPTEL: Java (ELITE), Data Science (ELITE + SILVER) **Achievements** 2nd Place in Python Hackathon (15 colleges, RVR&JC) **Find Me Online** LinkedIn, GitHub, Kaggle, HackerRank, CodeChef, LeetCode, Portfolio
6
+ '''
 
7
 
8
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
 
10
+ # Chatbot response function with integrated system message
11
  def respond(
12
  message,
13
  history: list[tuple[str, str]],
 
16
  temperature,
17
  top_p,
18
  ):
19
+ # System message defining assistant behavior
20
+ system_message = {
21
+ "role": "system",
22
+ "content": f"Act and chat as a professional fresher seeking a job and your name is SARATH. Here is about you: {data}. You should answer questions based on this information only."
23
+ }
24
+
25
+ messages = [system_message]
26
 
27
+ # Adding conversation history
28
  for val in history:
29
  if val[0]:
30
  messages.append({"role": "user", "content": val[0]})
31
  if val[1]:
32
  messages.append({"role": "assistant", "content": val[1]})
33
 
34
+ # Adding the current user input
35
  messages.append({"role": "user", "content": message})
36
 
37
  response = ""
38
 
39
+ # Streaming the response from the API
40
  for message in client.chat_completion(
41
  messages,
42
  max_tokens=max_tokens,
 
45
  top_p=top_p,
46
  ):
47
  token = message.choices[0].delta.content
 
48
  response += token
49
  yield response
50
 
51
 
52
+ # Gradio interface with additional sliders for control
 
 
53
  demo = gr.ChatInterface(
54
  respond,
55
  additional_inputs=[
56
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
57
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
58
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
59
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
 
 
 
 
 
 
60
  ],
61
  )
62
 
 
63
  if __name__ == "__main__":
64
  demo.launch()
65
+
66
+ # import gradio as gr
67
+ # from huggingface_hub import InferenceClient
68
+
69
+ # """
70
+ # 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
71
+ # """
72
+ # client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
73
+
74
+
75
+ # def respond(
76
+ # message,
77
+ # history: list[tuple[str, str]],
78
+ # system_message,
79
+ # max_tokens,
80
+ # temperature,
81
+ # top_p,
82
+ # ):
83
+ # messages = [{"role": "system", "content": system_message}]
84
+
85
+ # for val in history:
86
+ # if val[0]:
87
+ # messages.append({"role": "user", "content": val[0]})
88
+ # if val[1]:
89
+ # messages.append({"role": "assistant", "content": val[1]})
90
+
91
+ # messages.append({"role": "user", "content": message})
92
+
93
+ # response = ""
94
+
95
+ # for message in client.chat_completion(
96
+ # messages,
97
+ # max_tokens=max_tokens,
98
+ # stream=True,
99
+ # temperature=temperature,
100
+ # top_p=top_p,
101
+ # ):
102
+ # token = message.choices[0].delta.content
103
+
104
+ # response += token
105
+ # yield response
106
+
107
+
108
+ # """
109
+ # For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
110
+ # """
111
+ # demo = gr.ChatInterface(
112
+ # respond,
113
+ # additional_inputs=[
114
+ # gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
115
+ # gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
116
+ # gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
117
+ # gr.Slider(
118
+ # minimum=0.1,
119
+ # maximum=1.0,
120
+ # value=0.95,
121
+ # step=0.05,
122
+ # label="Top-p (nucleus sampling)",
123
+ # ),
124
+ # ],
125
+ # )
126
+
127
+
128
+ # if __name__ == "__main__":
129
+ # demo.launch()