Spaces:
Runtime error
Runtime error
Create app.py file
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
# Define the function to process the input
|
| 6 |
+
def process_input(user_input):
|
| 7 |
+
# Append "<mask>" to the user input
|
| 8 |
+
input_with_mask = user_input + " <mask>"
|
| 9 |
+
|
| 10 |
+
# Define the API endpoint and headers
|
| 11 |
+
url = "https://44ts8edkp0.execute-api.us-east-1.amazonaws.com/PROD/prompt-generation"
|
| 12 |
+
headers = {"Content-Type": "application/json"}
|
| 13 |
+
|
| 14 |
+
# Create the data payload
|
| 15 |
+
data = {"inputs": input_with_mask}
|
| 16 |
+
|
| 17 |
+
# Make the POST request
|
| 18 |
+
response = requests.post(url, headers=headers, data=json.dumps(data))
|
| 19 |
+
|
| 20 |
+
# Parse the JSON response
|
| 21 |
+
response_json = response.json()
|
| 22 |
+
|
| 23 |
+
# Extract the "sequence" values from the response
|
| 24 |
+
sequences = [item["sequence"] for item in response_json]
|
| 25 |
+
|
| 26 |
+
# Join the sequences into a single string for display
|
| 27 |
+
result = "\n".join(sequences)
|
| 28 |
+
|
| 29 |
+
return result
|
| 30 |
+
|
| 31 |
+
# Create the Gradio interface
|
| 32 |
+
iface = gr.Interface(
|
| 33 |
+
fn=process_input,
|
| 34 |
+
inputs="text",
|
| 35 |
+
outputs="text",
|
| 36 |
+
title="Text Masking and Sequence Generation",
|
| 37 |
+
description="Enter some text, and this app will append '<mask>' to it, send it to an API, and return the generated sequences."
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Launch the app
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
iface.launch()
|