Spaces:
Running
Running
File size: 6,563 Bytes
044b38d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
import gradio as gr
import random
import time
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain.chat_models import ChatOpenAI
from langchain.llms import OpenAI
import os
import json
import openai
import random
import asyncio
from langchain.prompts import (
ChatPromptTemplate,
HumanMessagePromptTemplate
)
from ast import literal_eval
from langchain.chat_models import ChatOpenAI
from langchain.schema import (
HumanMessage,
)
import json
from langchain.chat_models import ChatOpenAI
from langchain.llms import OpenAI
from langchain.chat_models import ChatAnthropic
from langchain.output_parsers import PydanticOutputParser
from pydantic import BaseModel, Field
from typing import List
import json
from ast import literal_eval
import os
import openai
import random
import time
import copy
import asyncio
from prompts import system_structure_template, system_epics_template, story_cards_template, schema_template, entities_template, update_schema_template, check_message_template, update_story_cards_template
import helper
myl = []
os.environ['OPENAI_API_KEY'] = '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'
openai.api_key = "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"
epics = []
latest_nums = []
# Deleting all the files after each update
for file in os.listdir():
if file.endswith('_gradio.json'):
helper.delete(file)
async def random_response(message, history, my_list=myl):
print(message)
if helper.Validating_Input(message): # Check if the question about gpt
return helper.apologise(random.randint(0,3))
if not helper.is_all_english_alpha_numeric_or_space(message): # Check if the non english text sent
return helper.apologise_lang(random.randint(0,3))
# ============================================================================================
if message.isnumeric():
latest_nums.append((int(message)+1))
if int(message)==1:
return helper.create_user_story()
elif int(message)==2:
latest_nums.append(-1)
return "Sorry, this option will be available in the next version!" + helper.choose()
else:
latest_nums.append(-1)
return 'return a valid number please'
if len(myl) == 0:
latest_nums.append(1)
myl.append(1)
return "Welcome to فزاع \n\n" + "Please write your systm discreption in order to build a system"
else:
if latest_nums[-1] not in [1,2,3]:
latest_nums.pop()
return 'return a valid number. ' + helper.choose()
if latest_nums[-1] == 1:
myl.append(1)
# First Prompt System Structure
start_time = time.time()
response = helper.first_prompt(system_name = message)
elapsed_time = time.time() - start_time
print(f"first_prompt {elapsed_time:.2f} seconds to run.")
# Second Prompt Epics
start_time = time.time()
epics = await helper.second_prompt(response, system_name = message)
elapsed_time = time.time() - start_time
print(f"epics {elapsed_time:.2f} seconds to run.")
# Third Prompt Entities
start_time = time.time()
entities = helper.third_prompt(epics)
elapsed_time = time.time() - start_time
print(f"entities {elapsed_time:.2f} seconds to run.")
# Fourth Prompt Data Schema
start_time = time.time()
all_schemas = await helper.fourth_prompt(entities, epics)
elapsed_time = time.time() - start_time
print(f"all_schemas {elapsed_time:.2f} seconds to run.")
# return markdown
output = helper.markdown('epics_gradio.json') + helper.choose()
latest_nums.append(-1)
return output
if latest_nums[-1] == 2:
# res = check('user story card', message).lower()
# print(res)
# if res == 'no':
# return apologise(random.randint(0,3))+"\n\n"+create_user_story()
start_time = time.time()
helper.affected_parts(user_request = message)
elapsed_time = time.time() - start_time
print(f"affected_parts {elapsed_time:.2f} seconds to run.")
output = ""
start_time = time.time()
new_card = helper.generate_story_cards(user_request = message)
elapsed_time = time.time() - start_time
print(f"generate_story_cards {elapsed_time:.2f} seconds to run.")
start_time = time.time()
output += helper.user_story_to_markdown(new_card) + "\n\n\n"
elapsed_time = time.time() - start_time
print(f"user_story_to_markdown {elapsed_time:.2f} seconds to run.")
start_time = time.time()
story_ids = helper.check_affected_story_ids()
elapsed_time = time.time() - start_time
print(f"check_affected_story_ids {elapsed_time:.2f} seconds to run.")
start_time = time.time()
if len(story_ids) != 0:
updated_cards = await helper.update_affected_story_cards(story_ids)
output += "=============================== The following is the affected user story card ==================================\n\n"
for card in updated_cards:
output += helper.user_story_to_markdown(card)
elapsed_time = time.time() - start_time
print(f"update_affected_story_cards {elapsed_time:.2f} seconds to run.")
output += helper.choose()
latest_nums.append(-1)
return output
|