Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""Untitled25.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colaboratory.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1i4BW958q6NUrUaJ2bAgNM8-N1pLSeP-Q
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
pip install openai streamlit
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
import openai
|
| 15 |
+
import streamlit as st
|
| 16 |
+
|
| 17 |
+
# Initialize OpenAI API and server base
|
| 18 |
+
openai.api_key = "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"
|
| 19 |
+
openai.api_base = "http://zanino.millennium.berkeley.edu:8000/v1"
|
| 20 |
+
|
| 21 |
+
# Set Streamlit layout
|
| 22 |
+
st.set_page_config(layout="wide")
|
| 23 |
+
|
| 24 |
+
# Function to get response from Gorilla Server
|
| 25 |
+
def get_gorilla_response(prompt, model):
|
| 26 |
+
try:
|
| 27 |
+
completion = openai.ChatCompletion.create(
|
| 28 |
+
model=model,
|
| 29 |
+
messages=[{"role": "user", "content": prompt}]
|
| 30 |
+
)
|
| 31 |
+
return completion.choices[0].message.content
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print("An error occurred:", e)
|
| 34 |
+
|
| 35 |
+
def main():
|
| 36 |
+
st.title("Gorilla LLM")
|
| 37 |
+
input_prompt = st.text_area("Enter your prompt:")
|
| 38 |
+
|
| 39 |
+
model_options = ('gorilla-7b-hf-v1', 'gorilla-mpt-7b-hf-v0')
|
| 40 |
+
option = st.selectbox('Select a model:', model_options)
|
| 41 |
+
|
| 42 |
+
if st.button("Create"):
|
| 43 |
+
if len(input_prompt) > 0:
|
| 44 |
+
result = get_gorilla_response(prompt=input_prompt, model=option)
|
| 45 |
+
st.write(result)
|
| 46 |
+
# ...
|
| 47 |
+
|
| 48 |
+
if st.button("Gorilla Magic"):
|
| 49 |
+
if len(input_prompt) > 0:
|
| 50 |
+
# ...
|
| 51 |
+
with col2:
|
| 52 |
+
code_result = extract_code_from_output(result)
|
| 53 |
+
if option == "gorilla-7b-hf-v1":
|
| 54 |
+
st.subheader("Generated Output")
|
| 55 |
+
st.code(code_result, language='python')
|
| 56 |
+
elif option == "gorilla-mpt-7b-hf-v0":
|
| 57 |
+
lines = code_result.split('\\n')
|
| 58 |
+
for line in lines[:-1]:
|
| 59 |
+
st.code(line, language='python')
|
| 60 |
+
# ...
|
| 61 |
+
run_generated_code(file_path)
|
| 62 |
+
|