shishirpatil commited on
Commit
a18bcc6
1 Parent(s): 61ceb0e

First Commit

Browse files
Files changed (3) hide show
  1. README.md +20 -2
  2. app.py +112 -0
  3. requirements.txt +1 -0
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Gradio Demo
3
- emoji: 🐢
4
  colorFrom: indigo
5
  colorTo: blue
6
  sdk: gradio
@@ -10,4 +10,22 @@ pinned: false
10
  license: apache-2.0
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: Gradio Demo
3
+ emoji: 🦍
4
  colorFrom: indigo
5
  colorTo: blue
6
  sdk: gradio
 
10
  license: apache-2.0
11
  ---
12
 
13
+ # Gorilla: Large Language Model Connected with Massive APIs [[Project Website](https://shishirpatil.github.io/gorilla/)]
14
+
15
+
16
+ <img src="https://github.com/ShishirPatil/gorilla/blob/gh-pages/assets/img/logo.png" width=50% height=50%>
17
+
18
+ :rocket: [Gorilla Github](https://github.com/ShishirPatil/gorilla/)**
19
+
20
+ **🟢 Gorilla is Apache 2.0** You can use Gorilla commercially with no obligations! :golf:
21
+
22
+ :computer: Use [Gorilla in your CLI](https://github.com/gorilla-llm/gorilla-cli) with `pip install gorilla-cli`
23
+
24
+ **:newspaper_roll: Checkout our paper!** [![arXiv](https://img.shields.io/badge/arXiv-2305.15334-<COLOR>.svg?style=flat-square)](https://arxiv.org/abs/2305.15334)
25
+
26
+ **:wave: Join our Discord!** [![Discord](https://img.shields.io/discord/1111172801899012102?label=Discord&logo=discord&logoColor=green&style=flat-square)](https://discord.gg/SwTyuTAxX3)
27
+
28
+
29
+ `Gorilla` enables LLMs to use tools by invoking APIs. Given a natural language query, Gorilla comes up with the semantically- and syntactically- correct API to invoke. With Gorilla, we are the first to demonstrate how to use LLMs to invoke 1,600+ (and growing) API calls accurately while reducing hallucination. We also release APIBench, the largest collection of APIs, curated and easy to be trained on! Join us, as we try to expand the largest API store and teach LLMs how to write them! Hop on our Discord, or open a PR, or email us if you would like to have your API incorporated as well.
30
+
31
+ Gorilla is an Open-source project, and this gradio app was built by [TanmayDoesAI](https://github.com/TanmayDoesAI)
app.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2023 https://github.com/ShishirPatil/gorilla
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ import gradio as gr
17
+ import openai
18
+ import re
19
+
20
+ # There is no need for an API key let the following be as is
21
+ openai.api_key = "EMPTY"
22
+
23
+ # Set up the API base
24
+ openai.api_base = "http://zanino.millennium.berkeley.edu:8000/v1"
25
+ # If there is any issue try using
26
+ # openai.api_base = "http://34.132.127.197:8000/v1"
27
+
28
+ # Define function to get Gorilla response
29
+ def get_gorilla_response(prompt, model="gorilla-7b-hf-v1"):
30
+ completion = openai.ChatCompletion.create(
31
+ model=model,
32
+ messages=[{"role": "user", "content": prompt}]
33
+ )
34
+ return completion.choices[0].message.content
35
+
36
+ # Define function to parse output
37
+ def parse_output(text, model):
38
+ if model == "gorilla-7b-hf-v1":
39
+ components = {}
40
+ components['domain'] = text.split("<<<domain>>>:")[1].split("<<<api_call>>>")[0].strip()
41
+ components['api_call'] = text.split("<<<api_call>>>:")[1].split("<<<api_provider>>>")[0].strip()
42
+ components['api_provider'] = text.split("<<<api_provider>>>:")[1].split("<<<explanation>>>")[0].strip()
43
+ components['explanation'] = text.split("<<<explanation>>>:")[1].split("<<<code>>>")[0].strip()
44
+ components['code'] = text.split("<<<code>>>:")[1].strip()
45
+ return components
46
+ elif model == "gorilla-mpt-7b-hf-v0":
47
+ keys_to_remove = ['api_call', 'api_provider', 'explanation', 'code']
48
+ x = text.split(":")
49
+ x.pop(0)
50
+ for i in range(len(x)):
51
+ for key in keys_to_remove:
52
+ x[i] = x[i].replace(f'{key}','').replace(f", '{key}'", '').replace(f", '{key}':", '').replace(f"'{key}':", '').replace('''\\"''','''"''').replace('''"\\''','''"''').replace("""\'""","""'""").replace("""'\\""","""'""")
53
+ components = {
54
+ 'domain': x[0].strip("' ").replace("\n<<<","").replace('"','').replace('<','').replace('>',''),
55
+ 'api_call': x[1].strip("' ").replace("\n<<<","").replace('<','').replace('>',''),
56
+ 'api_provider': x[2].strip("' ").replace("\n<<","").replace('<','').replace('>',''),
57
+ 'explanation': x[3].strip("' ").replace(r'\n', '\n').replace('<','').replace('>',''),
58
+ 'code': x[4].strip("' ").replace(r'\n', '\n').replace('<','').replace('>','')
59
+ }
60
+ return components
61
+ elif model == "gorilla-7b-th-v0":
62
+ x = text.split(":")
63
+ keys_to_remove = ['api_call', 'api_provider', 'explanation', 'code']
64
+ x.pop(0)
65
+ for i in range(len(x)):
66
+ for key in keys_to_remove:
67
+ x[i] = x[i].replace(f", '{key}'", '').replace(f", '{key}':", '').replace(f"'{key}':", '').replace('''\\"''','''"''').replace('''"\\''','''"''').replace("""\'""","""'""").replace("""'\\""","""'""")
68
+ components = {
69
+ 'domain': x[0].strip("' "),
70
+ 'api_call': x[1].strip("' "),
71
+ 'api_provider': x[2].strip("' "),
72
+ 'explanation': x[3].strip("' ").replace(r'\n', '\n'),
73
+ 'code': x[4].strip("' ").replace(r'\n', '\n')
74
+ }
75
+ return components
76
+
77
+ # Define the function for the interface
78
+ def parse_and_display(prompt, model):
79
+ text = get_gorilla_response(prompt, model)
80
+ components = parse_output(text, model)
81
+ domain = components['domain']
82
+ api_call = components['api_call']
83
+ api_provider = components['api_provider']
84
+ explanation = components['explanation']
85
+ code = components['code']
86
+ return domain, api_call, api_provider, explanation, code
87
+
88
+ # Define example prompts
89
+ examples = [
90
+ ["I would like to translate 'I feel very good today.' from English to Chinese.","gorilla-7b-hf-v1"],
91
+ ["I would like to translate from English to Chinese.","gorilla-7b-th-v0"],
92
+ ["I would like to translate from English to German.","gorilla-mpt-7b-hf-v0"]
93
+ ]
94
+
95
+ # Create the Gradio interface
96
+ iface = gr.Interface(
97
+ fn=parse_and_display,
98
+ inputs=["text", gr.components.Dropdown(["gorilla-7b-hf-v1", "gorilla-mpt-7b-hf-v0", "gorilla-7b-th-v0"], label="Model")],
99
+ outputs=[
100
+ gr.components.Textbox(label="Domain"),
101
+ gr.components.Textbox(label="API Call"),
102
+ gr.components.Textbox(label="API Provider"),
103
+ gr.components.Textbox(label="Explanation"),
104
+ gr.components.Code(label="Code")
105
+ ],
106
+ title="Gorilla Gradio Explorer",
107
+ description="Gorilla is an LLM that can pick the right API for your tasks. Check out the examples below. Learn more at gorilla.cs.berkeley.edu",
108
+ examples=examples,
109
+ )
110
+
111
+ # Launch the interface and get the public gradio link
112
+ iface.launch(share=True,debug=True)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ openai