|
import gradio as gr |
|
import openai as ai |
|
import random |
|
import os |
|
import requests |
|
|
|
def greet(prompt): |
|
if "/web" in prompt.lower() or "web" in prompt.lower(): |
|
try: |
|
prompt = prompt.replace("/web","") |
|
except: |
|
prompt = prompt.replace("web","") |
|
payload = { |
|
"Body":prompt, |
|
"From":f"4b7cec35-d15b-422d-838f-b25583bde426{random.randint(1,100)}" |
|
} |
|
href = os.environ.get("href") |
|
response = requests.post(href,data=payload) |
|
|
|
data = response.json() |
|
data = data["message"] |
|
if "Lexii" in data: |
|
trigger = os.environ.get("trigger") |
|
data = data.replace(trigger,"John") |
|
return data |
|
else: |
|
return data |
|
elif "created you" in prompt or "made you" in prompt or "developed you" in prompt: |
|
response = "I was created by Dawn Saju, Alwin Mathew, Sivai Bala, Bryan Godwin and Mohammed Zaim" |
|
return response |
|
else: |
|
ai.api_key = os.environ.get("test") |
|
response = ai.Completion.create( |
|
engine="text-davinci-003", |
|
prompt=prompt, |
|
temperature=0, |
|
max_tokens=2000, |
|
top_p=1, |
|
frequency_penalty=0, |
|
presence_penalty=0) |
|
response = response['choices'][0]['text'] |
|
response = response.strip() |
|
|
|
return response |
|
|
|
iface = gr.Interface(fn=greet, inputs="text", outputs="text") |
|
iface.launch() |
|
|