Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,86 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import json
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# Function to process all parameters including highlighted response
|
| 5 |
def process_all_parameters(article):
|
| 6 |
messages = [
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import os
|
| 3 |
import gradio as gr
|
| 4 |
import json
|
| 5 |
|
| 6 |
+
with open('mykey.txt', 'r') as file:
|
| 7 |
+
openai_key = file.read()
|
| 8 |
+
|
| 9 |
+
os.environ['OPENAI_API_KEY'] = openai_key
|
| 10 |
+
|
| 11 |
+
def agent(messages, model="gpt-4o-2024-08-06", temperature=0, presence_penalty=0, seed = 10, stream=False):
|
| 12 |
+
response = openai.chat.completions.create(
|
| 13 |
+
model=model,
|
| 14 |
+
messages=messages,
|
| 15 |
+
temperature=temperature,
|
| 16 |
+
presence_penalty=presence_penalty,
|
| 17 |
+
seed=seed,
|
| 18 |
+
stream = stream
|
| 19 |
+
)
|
| 20 |
+
return response.choices[0].message.content
|
| 21 |
+
|
| 22 |
+
system_message_1 = f"""
|
| 23 |
+
You are a Blog Editor at Analytics Vidhya, an edtech platform focused on creating learning content related to Data Science, AI, Machine Learning, and especially Generative AI. Your task is to critically evaluate and edit blogs based on the following criteria:
|
| 24 |
+
|
| 25 |
+
1) **Language & Grammar**: Ensure correct grammar, sentence structure, and overall readability.
|
| 26 |
+
2) **Word Usage**: Check for proper vocabulary, terminology, and accurate word choice.
|
| 27 |
+
3) **Flow & Structure**: Ensure logical progression, coherent structure, and readability.
|
| 28 |
+
4) **Technical Soundness**: Verify accuracy of technical content and ensure clear explanation of concepts.
|
| 29 |
+
5) **Reference Links**: Confirm the presence of appropriate reference links, especially when third-party information is mentioned.
|
| 30 |
+
6) **FAQs**: Assess whether FAQs are relevant, non-repetitive, and useful to the article.
|
| 31 |
+
|
| 32 |
+
For each parameter, rate the blog on a scale of 1 to 10 and provide **specific suggestions** for improvement with examples. Use the following JSON structure for each parameter:
|
| 33 |
+
- "Score": Rating out of 10
|
| 34 |
+
- "Suggestions": Specific feedback on how to improve
|
| 35 |
+
|
| 36 |
+
**Additional Requirements**:
|
| 37 |
+
- Provide the **Top 5 suggestions** for improving the article overall.
|
| 38 |
+
- Edit the article to incorporate your suggestions and ensure the final version is more than 90% human-written, even if the original text contains Generative AI content.
|
| 39 |
+
- Report the percentage of Generative AI content before and after editing.
|
| 40 |
+
- Finally, output everything in JSON format with these keys:
|
| 41 |
+
- "Word count"
|
| 42 |
+
- "Language & Grammar"
|
| 43 |
+
- "Word Usage"
|
| 44 |
+
- "Flow & Structure"
|
| 45 |
+
- "Technical Soundness"
|
| 46 |
+
- "Reference Links"
|
| 47 |
+
- "FAQs"
|
| 48 |
+
- "Top5 Suggestions"
|
| 49 |
+
- "Edited Article"
|
| 50 |
+
- "PreEditing GenAI Content%"
|
| 51 |
+
- "PostEditing GenAI Content%"
|
| 52 |
+
|
| 53 |
+
Ensure the output is formatted correctly for use with the Python `json` library.
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
example = """
|
| 58 |
+
~~<span style="color:red">This text has been removed from the original article.</span>~~
|
| 59 |
+
<span style="color:green">This new text is added in the edited article.</span>
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
system_message_2 = f"""
|
| 63 |
+
You are a text comparison tool designed to compare the original article with the edited version and highlight the differences between them.
|
| 64 |
+
|
| 65 |
+
Your task is to:
|
| 66 |
+
1. **Highlight deletions** in the original article with a red strikethrough using Markdown and HTML.
|
| 67 |
+
2. **Highlight additions** in the edited article using green text.
|
| 68 |
+
|
| 69 |
+
Format your output using Markdown with embedded HTML tags, which can be displayed using Ipython's Markdown function.
|
| 70 |
+
|
| 71 |
+
- **Deletions**: Mark text removed from the original article with a red strikethrough, like this:
|
| 72 |
+
`~~<span style="color:red">Deleted text</span>~~`.
|
| 73 |
+
- **Additions**: Mark text added in the edited article with green text, like this:
|
| 74 |
+
`<span style="color:green">Added text</span>`.
|
| 75 |
+
|
| 76 |
+
Example format:
|
| 77 |
+
{example}
|
| 78 |
+
|
| 79 |
+
Make sure to apply these formatting rules consistently throughout the entire comparison.
|
| 80 |
+
"""
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
# Function to process all parameters including highlighted response
|
| 85 |
def process_all_parameters(article):
|
| 86 |
messages = [
|