MGV12 commited on
Commit
8b0bd1e
1 Parent(s): 09642d5

Upload Mllama2gradio.ipynb

Browse files
Files changed (1) hide show
  1. Mllama2gradio.ipynb +177 -0
Mllama2gradio.ipynb ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stderr",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
13
+ "spyder 5.4.1 requires setuptools>=49.6.0, but you have setuptools 41.2.0 which is incompatible.\n"
14
+ ]
15
+ }
16
+ ],
17
+ "source": [
18
+ "!pip install gradio -q\n",
19
+ "!pip install --upgrade fireworks-ai -q"
20
+ ]
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "execution_count": 2,
25
+ "metadata": {},
26
+ "outputs": [],
27
+ "source": [
28
+ "from fireworks.client import Fireworks"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": 3,
34
+ "metadata": {},
35
+ "outputs": [],
36
+ "source": [
37
+ "import gradio as gr\n",
38
+ "\n",
39
+ "history = []\n",
40
+ "def user_message(inquiry):\n",
41
+ " user_message = (\n",
42
+ " f\"\"\"\n",
43
+ " You are a bank customer service bot. Your task is to assess customer intent\n",
44
+ " and categorize customer inquiry after <<<>>> into one of the following predefined categories:\n",
45
+ "\n",
46
+ " card arrival\n",
47
+ " change pin\n",
48
+ " exchange rate\n",
49
+ " country support\n",
50
+ " cancel transfer\n",
51
+ " charge dispute\n",
52
+ "\n",
53
+ " If the text doesn't fit into any of the above categories, classify it as:\n",
54
+ " customer service\n",
55
+ "\n",
56
+ " You will only respond with the predefined category. Do not include the word \"Category\". Do not provide explanations or notes.\n",
57
+ "\n",
58
+ " ####\n",
59
+ " Here are some examples:\n",
60
+ "\n",
61
+ " Inquiry: How do I know if I will get my card, or if it is lost? I am concerned about the delivery process and would like to ensure that I will receive my card as expected. Could you please provide information about the tracking process for my card, or confirm if there are any indicators to identify if the card has been lost during delivery?\n",
62
+ " Category: card arrival\n",
63
+ " Inquiry: I am planning an international trip to Paris and would like to inquire about the current exchange rates for Euros as well as any associated fees for foreign transactions.\n",
64
+ " Category: exchange rate\n",
65
+ " Inquiry: What countries are getting support? I will be traveling and living abroad for an extended period of time, specifically in France and Germany, and would appreciate any information regarding compatibility and functionality in these regions.\n",
66
+ " Category: country support\n",
67
+ " Inquiry: Can I get help starting my computer? I am having difficulty starting my computer, and would appreciate your expertise in helping me troubleshoot the issue.\n",
68
+ " Category: customer service\n",
69
+ " ###\n",
70
+ "\n",
71
+ " <<<\n",
72
+ " Inquiry: {inquiry}\n",
73
+ " >>>\n",
74
+ " \"\"\"\n",
75
+ " )\n",
76
+ " return user_message"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 4,
82
+ "metadata": {},
83
+ "outputs": [],
84
+ "source": [
85
+ "def echo(message, history):\n",
86
+ " client = Fireworks(api_key=\"SwGXPje77jqsQcnaT6BuGYG1G8yeHt9FQjZXX7RzGfEbkXej\")\n",
87
+ " message_modified = user_message(message)\n",
88
+ "\n",
89
+ " response = client.chat.completions.create(\n",
90
+ " model=\"accounts/fireworks/models/llama-v2-7b-chat\",\n",
91
+ " messages=[{\"role\": \"user\", \"content\": message_modified}],)\n",
92
+ "\n",
93
+ " bot_response = response.choices[0].message.content\n",
94
+ "\n",
95
+ " history.append([message, bot_response])\n",
96
+ "\n",
97
+ " return bot_response\n",
98
+ " # return message"
99
+ ]
100
+ },
101
+ {
102
+ "cell_type": "code",
103
+ "execution_count": 5,
104
+ "metadata": {},
105
+ "outputs": [
106
+ {
107
+ "name": "stdout",
108
+ "output_type": "stream",
109
+ "text": [
110
+ "Running on local URL: http://127.0.0.1:7860\n",
111
+ "\n",
112
+ "To create a public link, set `share=True` in `launch()`.\n"
113
+ ]
114
+ },
115
+ {
116
+ "data": {
117
+ "text/html": [
118
+ "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
119
+ ],
120
+ "text/plain": [
121
+ "<IPython.core.display.HTML object>"
122
+ ]
123
+ },
124
+ "metadata": {},
125
+ "output_type": "display_data"
126
+ },
127
+ {
128
+ "name": "stdout",
129
+ "output_type": "stream",
130
+ "text": [
131
+ "Keyboard interruption in main thread... closing server.\n"
132
+ ]
133
+ },
134
+ {
135
+ "data": {
136
+ "text/plain": []
137
+ },
138
+ "execution_count": 5,
139
+ "metadata": {},
140
+ "output_type": "execute_result"
141
+ }
142
+ ],
143
+ "source": [
144
+ "demo = gr.ChatInterface(fn=echo, examples=[\"What countries are getting support? I will be traveling and living abroad for an extended period of time, specifically in France and Germany, and would appreciate any information regarding compatibility and functionality in these regions.\", \"Can I get help starting my computer? I am having difficulty starting my computer, and would appreciate your expertise in helping me troubleshoot the issue.\"], title=\"Echo Bot\")\n",
145
+ "demo.launch(debug = True)"
146
+ ]
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "execution_count": null,
151
+ "metadata": {},
152
+ "outputs": [],
153
+ "source": []
154
+ }
155
+ ],
156
+ "metadata": {
157
+ "kernelspec": {
158
+ "display_name": "base",
159
+ "language": "python",
160
+ "name": "python3"
161
+ },
162
+ "language_info": {
163
+ "codemirror_mode": {
164
+ "name": "ipython",
165
+ "version": 3
166
+ },
167
+ "file_extension": ".py",
168
+ "mimetype": "text/x-python",
169
+ "name": "python",
170
+ "nbconvert_exporter": "python",
171
+ "pygments_lexer": "ipython3",
172
+ "version": "3.10.9"
173
+ }
174
+ },
175
+ "nbformat": 4,
176
+ "nbformat_minor": 2
177
+ }