Dhamodhar Tv commited on
Commit
d607c88
·
1 Parent(s): 0562af8

gradio file was added

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import urllib.parse
4
+ import tkinter as tk
5
+ from tkinter import messagebox
6
+
7
+ openai.api_key = "YOUR_OPENAI_API_KEY"
8
+
9
+ def raise_issue(e, model, prompt):
10
+ issue_title = urllib.parse.quote("[bug] Hosted Gorilla: <Issue>")
11
+ issue_body = urllib.parse.quote(f"Exception: {e}\nFailed model: {model}, for prompt: {prompt}")
12
+ issue_url = f"https://github.com/ShishirPatil/gorilla/issues/new?assignees=&labels=hosted-gorilla&projects=&template=hosted-gorilla-.md&title={issue_title}&body={issue_body}"
13
+ print(f"An exception has occurred: {e}\nPlease raise an issue here: {issue_url}")
14
+
15
+ def get_gorilla_response(prompt, model):
16
+ try:
17
+ completion = openai.ChatCompletion.create(
18
+ model=model,
19
+ messages=[{"role": "user", "content": prompt}]
20
+ )
21
+ return completion.choices[0].message.content
22
+ except Exception as e:
23
+ raise_issue(e, model, prompt)
24
+
25
+ iface = gr.Interface(
26
+ fn=get_gorilla_response,
27
+ inputs=["text", gr.inputs.Dropdown(["gorilla-7b-hf-v1", "gorilla-7b-tf-v0", "gorilla-7b-th-v0"])],
28
+ outputs=gr.outputs.Textbox(label="Response"),
29
+ live=False,
30
+ title="Gorilla Response App",
31
+ description="Enter a query and select a Gorilla model to get a response."
32
+ )
33
+
34
+ # Launch the interface
35
+ if __name__ == "__main__":
36
+ iface.launch(share=True)