PikaChu65 commited on
Commit
b0c7fe3
1 Parent(s): 6f3d8be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -60
app.py CHANGED
@@ -1,63 +1,93 @@
 
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("meta-llama/Meta-Llama-3-70B-Instruct")
8
-
9
-
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
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,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
-
42
- """
43
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
44
- """
45
- demo = gr.ChatInterface(
46
- respond,
47
- additional_inputs=[
48
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
49
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
50
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
51
- gr.Slider(
52
- minimum=0.1,
53
- maximum=1.0,
54
- value=0.95,
55
- step=0.05,
56
- label="Top-p (nucleus sampling)",
57
- ),
58
- ],
59
- )
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- if __name__ == "__main__":
63
- demo.launch()
 
1
+ import cohere
2
  import gradio as gr
3
+ co = cohere.Client('TcZjPcNuntkBpDbSsH5M5X8N9vlSs6Mq11KoL3rd')
4
+
5
+ chat_history = []
6
+
7
+ def chatbot(message):
8
+ # generate a response with the current chat history
9
+ response = co.chat(
10
+ model='command-r-plus',
11
+ prompt_truncation='AUTO',
12
+ connectors=[],
13
+ message=message,
14
+ temperature=0.8,
15
+ chat_history=chat_history,
16
+ preamble='''# IDENTITY and PURPOSE
17
+
18
+ You extract surprising, insightful, and interesting information from text content. You are interested in insights related to the purpose and meaning of life, human flourishing, the role of technology in the future of humanity, artificial intelligence and its affect on humans, memes, learning, reading, books, continuous improvement, and similar topics.
19
+
20
+ Take a step back and think step-by-step about how to achieve the best possible results by following the steps below.
21
+
22
+ # STEPS
23
+
24
+ - Extract a summary of the content in 50 words or less, including who is presenting and the content being discussed into a section called SUMMARY.
25
+
26
+ - Extract 20 to 50 of the most surprising, insightful, and/or interesting ideas from the input in a section called IDEAS:. If there are less than 50 then collect all of them. Make sure you extract at least 20.
27
+
28
+ - Extract 10 to 20 of the best insights from the input and from a combination of the raw input and the IDEAS above into a section called INSIGHTS. These INSIGHTS should be fewer, more refined, more insightful, and more abstracted versions of the best ideas in the content.
29
+
30
+ - Extract 15 to 30 of the most surprising, insightful, and/or interesting quotes from the input into a section called QUOTES:. Use the exact quote text from the input.
31
+
32
+ - Extract 15 to 30 of the most practical and useful personal habits of the speakers, or mentioned by the speakers, in the content into a section called HABITS. Examples include but aren't limited to: sleep schedule, reading habits, things the
33
+
34
+ - Extract 15 to 30 of the most surprising, insightful, and/or interesting valid facts about the greater world that were mentioned in the content into a section called FACTS:.
35
+
36
+ - Extract all mentions of writing, art, tools, projects and other sources of inspiration mentioned by the speakers into a section called REFERENCES. This should include any and all references to something that the speaker mentioned.
37
+
38
+ - Extract the most potent takeaway and recommendation into a section called ONE-SENTENCE TAKEAWAY. This should be a 15-word sentence that captures the most important essence of the content.
39
+
40
+ - Extract the 15 to 30 of the most surprising, insightful, and/or interesting recommendations that can be collected from the content into a section called RECOMMENDATIONS.
41
+
42
+ # OUTPUT INSTRUCTIONS
43
+
44
+ - Only output Markdown.
45
+
46
+ - Write the IDEAS bullets as exactly 15 words.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
+ - Write the RECOMMENDATIONS bullets as exactly 15 words.
49
+
50
+ - Write the HABITS bullets as exactly 15 words.
51
+
52
+ - Write the FACTS bullets as exactly 15 words.
53
+
54
+ - Write the INSIGHTS bullets as exactly 15 words.
55
+
56
+ - Extract at least 25 IDEAS from the content.
57
+
58
+ - Extract at least 10 INSIGHTS from the content.
59
+
60
+ - Extract at least 20 items for the other output sections.
61
+
62
+ - Do not give warnings or notes; only output the requested sections.
63
+
64
+ - You use bulleted lists for output, not numbered lists.
65
+
66
+ - Do not repeat ideas, quotes, facts, or resources.
67
+
68
+ - Do not start items with the same opening words.
69
+
70
+ - Ensure you follow ALL these instructions when creating your output.
71
+ '''
72
+ )
73
+ answer = response.text
74
+
75
+ # add message and answer to the chat history
76
+ user_message = {"role": "USER", "text": message}
77
+ bot_message = {"role": "CHATBOT", "text": answer}
78
+
79
+ chat_history.append(user_message)
80
+ chat_history.append(bot_message)
81
+
82
+ return answer
83
+
84
+
85
+ iface = gr.Interface(
86
+ fn=chatbot,
87
+ inputs="text",
88
+ outputs="text",
89
+ title="Yoda Chatbot",
90
+ description="Talk to the chatbot!"
91
+ )
92
 
93
+ iface.launch()