Spaces:
Runtime error
Runtime error
first
Browse files
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# def load_css():
|
| 4 |
+
# with open('app.css', 'r') as file:
|
| 5 |
+
# return file.read()
|
| 6 |
+
|
| 7 |
+
def translate_fortran_to_rust(fortran_code):
|
| 8 |
+
"""Translate Fortran code to Rust using the provided model."""
|
| 9 |
+
# Translation logic, with example stubbed function call
|
| 10 |
+
# rust_code = inference.testing(fortran_code)
|
| 11 |
+
return fortran_code
|
| 12 |
+
|
| 13 |
+
default_codes = """
|
| 14 |
+
program sum_of_numbers\n
|
| 15 |
+
implicit none\n
|
| 16 |
+
integer :: n, i, sum\n\n
|
| 17 |
+
! Initialize variables\n
|
| 18 |
+
sum = 0\n\n
|
| 19 |
+
! Get user input\n
|
| 20 |
+
print *, \Enter a positive integer:\\n
|
| 21 |
+
read *, n\n\n
|
| 22 |
+
! Calculate the sum of numbers from 1 to n\n
|
| 23 |
+
do i = 1, n\n
|
| 24 |
+
sum = sum + i\n
|
| 25 |
+
end do\n\n
|
| 26 |
+
! Print the result\n
|
| 27 |
+
print *, \The sum of numbers from 1 to\, n, \is\, sum\n
|
| 28 |
+
end program sum_of_numbers
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
default_explanation ="""
|
| 32 |
+
The provided Fortran code snippet is a program that calculates the sum of integers from 1 to n, where n is provided by the user.
|
| 33 |
+
It uses a simple procedural approach, including variable declarations, input handling, and a loop for the summation.\n\n
|
| 34 |
+
The functionality of the program is explained in detail in the elaboration. The program starts by initializing variables and prompting the user for input.
|
| 35 |
+
It then calculates the sum using a do loop, iterating from 1 to n, and accumulating the result in a variable. Finally, it prints the computed sum to the console.\n\n
|
| 36 |
+
This program demonstrates a straightforward application of Fortran's capabilities for handling loops and basic arithmetic operations.
|
| 37 |
+
It is a clear example of how Fortran can be used to solve mathematical problems involving user interaction and iterative computations.
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
# Create the interface
|
| 41 |
+
|
| 42 |
+
# Create and launch the Gradio interfac
|
| 43 |
+
iface = gr.Interface(
|
| 44 |
+
fn=translate_fortran_to_rust,
|
| 45 |
+
inputs=[
|
| 46 |
+
"textbox",
|
| 47 |
+
],
|
| 48 |
+
outputs="textbox"
|
| 49 |
+
# gr.Textbox(
|
| 50 |
+
# lines=10,
|
| 51 |
+
# label="Rust Code"
|
| 52 |
+
# )
|
| 53 |
+
# title="Fortran to Rust Code Translator",
|
| 54 |
+
# description=(
|
| 55 |
+
# "This tool translates Fortran code to Rust using a language model.\n\n"
|
| 56 |
+
# "How to use:\n"
|
| 57 |
+
# "1. Enter your Fortran code in the first text box\n"
|
| 58 |
+
# "2. Add an explanation of the code in the second text box\n"
|
| 59 |
+
# "3. The translated Rust code will appear in the output box\n\n"
|
| 60 |
+
# "Note: The default model is a Llama-3.2-3B-Instruct"
|
| 61 |
+
# ),
|
| 62 |
+
# examples=[
|
| 63 |
+
# [default_codes, default_explanation],
|
| 64 |
+
# ]
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
iface.launch()
|